Phone end insert emoji expression, save to database times wrong:
caused By:java.sql.SQLException:Incorrect string value: ' \xf0\x9f\x98\x84 ' forColumn ' Review ' at row 1At 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)
Check Reason:
The UTF-8 encoding can be two, three, and four bytes. The emoji expression is 4 bytes, while MySQL UTF8 encodes up to 3 bytes, so data cannot be plugged in.
Solution: Convert the MySQL encoding from UTF8 to UTF8MB4.
Command:ALTER TABLECHARACTER SET
Command: ALTER TABLE ' table_name ' MODIFY COLUMN ' column_name ' text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Reference:
Http://stackoverflow.com/questions/2108824/mysql-incorrect-string-value-error-when-save-unicode-string-in-django
Http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-charsets.html
Let MySQL support emoji emoticons (4 bytes UTF8 character save method in MySQL)