这是我的连接设置:
Connection conn = DriverManager。getConnection(url + dbName + "?useUnicode=true&characterEncoding=utf-8",用户名,密码);
我得到以下错误时轮胎添加一行到一个表:
错误的字符串值:'\xF0\x90\x8D\x83\xF0\x90…在第1行为“content”列
我插入数千条记录,当文本包含\xF0时,我总是得到这个错误(即不正确的字符串值总是以\xF0开始)。
列的排序规则是utf8_general_ci。
有什么问题吗?
这不是推荐的解决方案。但值得分享。因为我的项目是升级数据库从旧的Mysql到最新的(8).但我不能改变表结构,只有数据库配置(Mysql)。mysql服务器的解决方案。
Windows测试
mysql 8.0.15
在mysql配置中搜索
sql模式= "…"
取消它。或者在我的例子中,只需输入/添加
sql模式= " NO_ENGINE_SUBSTITUTION "
为什么不推荐解决方案。因为如果你用拉丁语(我的情况)..数据插入成功,但没有插入内容(mysql没有响应错误!!)例如,你输入这样的信息
等等 \x12
它保存
[盒子]
好吧. .对于我的问题…我可以把字段改为UTF8..但是有一个小问题。参见上面关于其他解决方案失败的答案,因为字没有插入,因为包含超过2个字节(cmiiw)..这个解决方案使您的插入数据变成方框。合理的是使用blob..你可以跳过我的回答。
另一个与此相关的测试是..在保存之前对代码使用utf8_encode。我使用latin1和它是成功的(我不使用sql模式)!与上面使用base64_encode的答案相同。
我的建议是分析你的表格需求,并尝试从其他格式改为UTF8
我的PLAY Java应用程序有这个问题。这是我对该异常的堆栈跟踪:
javax.persistence.PersistenceException: Error[Incorrect string value: '\xE0\xA6\xAC\xE0\xA6\xBE...' for column 'product_name' at row 1]
at io.ebean.config.dbplatform.SqlCodeTranslator.translate(SqlCodeTranslator.java:52)
at io.ebean.config.dbplatform.DatabasePlatform.translate(DatabasePlatform.java:192)
at io.ebeaninternal.server.persist.dml.DmlBeanPersister.execute(DmlBeanPersister.java:83)
at io.ebeaninternal.server.persist.dml.DmlBeanPersister.insert(DmlBeanPersister.java:49)
at io.ebeaninternal.server.core.PersistRequestBean.executeInsert(PersistRequestBean.java:1136)
at io.ebeaninternal.server.core.PersistRequestBean.executeNow(PersistRequestBean.java:723)
at io.ebeaninternal.server.core.PersistRequestBean.executeNoBatch(PersistRequestBean.java:778)
at io.ebeaninternal.server.core.PersistRequestBean.executeOrQueue(PersistRequestBean.java:769)
at io.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:456)
at io.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:406)
at io.ebeaninternal.server.persist.DefaultPersister.save(DefaultPersister.java:393)
at io.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1602)
at io.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1594)
at io.ebean.Model.save(Model.java:190)
at models.Product.create(Product.java:147)
at controllers.PushData.xlsupload(PushData.java:67)
at router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$40(Routes.scala:690)
at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:134)
at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:133)
at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$8$$anon$2$$anon$1.invocation(HandlerInvoker.scala:108)
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:88)
at play.http.DefaultActionCreator$1.call(DefaultActionCreator.java:31)
at play.core.j.JavaAction.$anonfun$apply$8(JavaAction.scala:138)
at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:655)
at scala.util.Success.$anonfun$map$1(Try.scala:251)
at scala.util.Success.map(Try.scala:209)
at scala.concurrent.Future.$anonfun$map$1(Future.scala:289)
at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
at scala.concurrent.impl.CallbackRunnable.run$$$capture(Promise.scala:60)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala)
at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:56)
at play.api.libs.streams.Execution$trampoline$.execute(Execution.scala:70)
at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:48)
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:68)
at scala.concurrent.impl.Promise$KeptPromise$Kept.onComplete(Promise.scala:368)
at scala.concurrent.impl.Promise$KeptPromise$Kept.onComplete$(Promise.scala:367)
at scala.concurrent.impl.Promise$KeptPromise$Successful.onComplete(Promise.scala:375)
at scala.concurrent.impl.Promise.transform(Promise.scala:29)
at scala.concurrent.impl.Promise.transform$(Promise.scala:27)
at scala.concurrent.impl.Promise$KeptPromise$Successful.transform(Promise.scala:375)
at scala.concurrent.Future.map(Future.scala:289)
at scala.concurrent.Future.map$(Future.scala:289)
at scala.concurrent.impl.Promise$KeptPromise$Successful.map(Promise.scala:375)
at scala.concurrent.Future$.apply(Future.scala:655)
at play.core.j.JavaAction.apply(JavaAction.scala:138)
at play.api.mvc.Action.$anonfun$apply$2(Action.scala:96)
at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:304)
at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
at scala.concurrent.impl.CallbackRunnable.run$$$capture(Promise.scala:60)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.sql.SQLException: Incorrect string value: '\xE0\xA6\xAC\xE0\xA6\xBE...' for column 'product_name' at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
at io.ebeaninternal.server.type.DataBind.executeUpdate(DataBind.java:82)
at io.ebeaninternal.server.persist.dml.InsertHandler.execute(InsertHandler.java:122)
at io.ebeaninternal.server.persist.dml.DmlBeanPersister.execute(DmlBeanPersister.java:73)
... 59 more
我想用io.Ebean保存一条记录。我通过使用utf8mb4排序规则重新创建我的数据库来修复它,并应用play evolution重新创建所有表,以便所有表都应该使用utf-8排序规则重新创建。
CREATE DATABASE inventory CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;