\ xF0 \ x9F \ x98 \ x94错误字符串值sql异常的原因?

时间:2018-08-20 05:58:31

标签: mysql grails

在日志中,出现以下错误。当将字符串\ xF0 \ x9F \ x98 \ x94作为参数传递时,将发生错误。此值无法保存到表中,因此会引发不正确的字符串值错误。我想知道传递这种价值的原因是什么。这是黑客尝试吗?我不知道\ xF0 \ x9F \ x98 \ x94作为邮政表格参数传递时意味着什么。感谢您的帮助!谢谢!

ERROR 2018-08-19 16:14:40,369 [ajp-bio-8109-exec-2808] util.JDBCExceptionReporter: Incorrect string value: '\xF0\x9F\x98\x94 B...' for column 'body' at row 1
ERROR 2018-08-19 16:14:40,372 [ajp-bio-8109-exec-2808] events.PatchedDefaultFlushEventListener: Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not update: [EventEmailDraft#42]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x94 B...' for column 'body' at row 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4098)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4030)
    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:2677)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2134)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2434)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2352)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2337)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    ... 3 more
ERROR 2018-08-19 16:14:40,377 [ajp-bio-8109-exec-2808] errors.GrailsExceptionResolver: SQLException occurred when processing request: [POST] /roadrace/message/saveDraft
Incorrect string value: '\xF0\x9F\x98\x94 B...' for column 'body' at row 1. Stacktrace follows:
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not update: [EventEmailDraft#42]; uncategorized SQLException for SQL [update event_email_draft set version=?, body=?, emails=?, event_id=?, subject=? where id=? and version=?]; SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\x9F\x98\x94 B...' for column 'body' at row 1; nested exception is java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x94 B...' for column 'body' at row 1
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x94 B...' for column 'body' at row 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4098)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4030)
    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:2677)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2134)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2434)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2352)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2337)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
    ... 3 more

1 个答案:

答案 0 :(得分:2)

这是由3个以上字节组成的Unicode序列

groovy:000> new String([0xF0, 0x9F, 0x98, 0x94] as byte[], 'UTF-8')
===> 

MySQL中UTF-8的默认值仅保留3个字节。

在这里What is the difference between utf8mb4 and utf8 charsets in mysql?中可以找到适当的解释,在这里也可以回答诸如“我该如何改变”之类的后续问题。