我实际上已在Stackoverflow上多次发现此问题,但解决方案对我没有帮助.
我在我的Android应用程序中有一个聊天模块,并希望在我的服务器数据库中保留消息,这可以正常工作,直到出现像emojis这样的特殊字符.
ERROR: Incorrect string value: '\xF0\x9F\x98\x81' for column 'message' at row 1
...
...
Caused by: java.sql.sqlException: Incorrect string value: '\xF0\x9F\x98\x81' for column 'message' at row 1
at com.MysqL.jdbc.sqlError.createsqlException(sqlError.java:1084)
at com.MysqL.jdbc.MysqLIO.checkErrorPacket(MysqLIO.java:4232)
at com.MysqL.jdbc.MysqLIO.checkErrorPacket(MysqLIO.java:4164)
at com.MysqL.jdbc.MysqLIO.sendCommand(MysqLIO.java:2615)
at com.MysqL.jdbc.MysqLIO.sqlQueryDirect(MysqLIO.java:2776)
at com.MysqL.jdbc.ConnectionImpl.execsql(ConnectionImpl.java:2838)
at com.MysqL.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
at com.MysqL.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2334)
at com.MysqL.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2262)
at com.MysqL.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2246)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:187)
... 23 more
我的环境是:
-MysqL 5.6
-Tomcat 8.0.8
-Hibernate 4.3.5
-JDK 1.8.0_05
这是带有问题的列的用过的表’message’:
这些是我在persistence.xml(2.1版)中的属性:
MysqL.jdbc.Driver" />
MysqL://localhost:3306/gamedb?useUnicode=true&characterEncoding=UTF-8" />
MysqL5Dialect" />
-Change datatype of 'message' from varchar to longtext
-Change collation of 'message' to utf8mb4
-Change collation of table to utf8mb4
-Append url with "?useUnicode=true&characterEncoding=UTF-8"
-Set character-set-server of MysqL to utf8mb4
最佳答案
原文链接:https://www.f2er.com/mysql/433799.html