【发布时间】:2011-12-22 12:25:18
【问题描述】:
我正在尝试将以下推文存储到 MySQL 数据库中,但失败并出现以下异常。我如何解决它?任何帮助表示赞赏。我正在使用 utf8 字符集数据库,我认为消息中的 !??? 在这里有问题。
tweet=由于我的身高,我在 USS 被禁止乘车,我想坐在中间,以防万一发生意外,但我仍然爱我的身高!???
Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\x8D\xF0\x9F...' for column 'message' at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2345)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2330)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
【问题讨论】:
-
我感觉到两个可能的问题。 1. ' 和 2. @。尝试从字符串中删除两者并尝试保存。
-
' 对我来说似乎更有问题。您的更新语法是什么样的?我打赌你正在使用内联 SQL,它为 SQL 注入打开了大门。您应该真正使用参数。它将消除您的问题并提高代码的安全性。