Get user nickname nickname with emoji expression, converted to character code is this form "\xf0\x9f\x91\x8d\xe6\x94 ...",
The following error may occur with direct save
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.
Step 1: Modify the My.ini file [mysqld] Character-set-server=utf8mb4
Step 2: In the connector/j connection parameter, do not add characterencoding parameters. When this parameter is not added, the default value is AutoDetect.
jdbc.driver_class com.mysql.jdbc.Driverjdbc.url jdbc\:mysql\: // 127.0.0.1\:3306/jlbmg?useunicode\=true#&characterencoding\=UTF8 jdbc.username rootjdbc.password Root
Step 3: Convert the already built tables to UTF8MB4
Command:ALTER TABLE ' table_name ' CONVERT to CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; (table_ Name replaced with your table name)
Alter Table Convert to character set utf8mb4 collate utf8mb4_general_ci;
Step 4: set the type of field that you want to use emoji to UTF8MB4:
Command:altertablecolumn ' column_name ' textcharacter Set utf8mb4 collate utf8mb4_general_ci;
Step 5: Restart MySQL:
Start-to-run->cmd
Stop: net stop MySQL
Startup: net start MySQL
MySQL Storage emoji Emoticons