代码之家  ›  专栏  ›  技术社区  ›  kofhearts

导致\xF0\x9F\x98\x94字符串值不正确的sql异常的原因?

  •  0
  • kofhearts  · 技术社区  · 6 年前

    日志中有以下错误。当字符串\xF0\x9F\x98\x94作为参数传递时发生错误。无法将此值保存到表中,因此它引发不正确的字符串值错误。我想知道传递这种价值的原因是什么。是黑客攻击吗?我不知道当作为post form param传递时\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 回复  |  直到 6 年前
        1
  •  2
  •   cfrick    6 年前

    这是包含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?