Solution for inputting Emoji emojis into MySQL database: emojimysql
When the mobile app comments, it restores the emoticon and prompts "failed.
1. Check the tomcat background log. The core error message is as follows:
Caused by: java. SQL. SQLException: Incorrect string value: '\ xF0 \ x9F \ x98 \ x97 \ xF0 \ x9F...' for column 'content' at row 1
At 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.exe cSQL (ConnectionImpl. java: 2734)
At com.mysql.jdbc.PreparedStatement.exe cuteInternal (PreparedStatement. java: 2155)
At com.mysql.jdbc.PreparedStatement.exe cute (PreparedStatement. java: 1379)
At org.apache.commons.dbcp.DelegatingPreparedStatement.exe cute (DelegatingPreparedStatement. java: 172)
At org.apache.commons.dbcp.DelegatingPreparedStatement.exe cute (DelegatingPreparedStatement. java: 172)
At com.ibatis.sqlmap.engine.execution.SqlExecutor.exe cuteUpdate (SqlExecutor. java: 80)
At com. ibatis. sqlmap. engine. mapping. statement. MappedStatement. sqlExecuteUpdate (MappedStatement. java: 216)
At com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.exe cuteUpdate (MappedStatement. java: 94)
... 46 more
[Root @ mysqlvm2 ~] # Mysql-root-p
Mysql> use test;
Database changed
Mysql> show tables;
Ignoring query to other database
Mysql> Ctrl-C -- exit!
Aborted
If you forget to enter the-u parameter, rinse your input, OK, as shown below:
[Root @ mysqlvm2 ~] # Mysql-uroot-p
Enter password:
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 4
Server version: 5.6.12-log Source distribution
Copyright (c) 2000,201 1, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.
Mysql>
Mysql> use test;
Database changed
Mysql> show tables;
+ ------------------------ +
| Tables_in_test |
+ ------------------------ +
| C |
| Lubin_test |
| Test |
| Tt |
+ ------------------------ +
10 rows in set (0.00 sec)
Input Incorrect string value: '\ xF0 \ x9F \ x98 \ x97 \ xF0 \ x9F... 'problem, most of them are character sets. Previously I changed from latain to gbk, from gbk to utf8, and my CONTENT field has been utf8, so more than utf8 is only utf8mb4, so modify the character set of the table field.
Mysql>
2. Modify the character set of the table field to utf8mb4:
Alter table UGC_REVIEW_CONTENT MODIFY 'content' text character set utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT 'comment content ';
After the test, the app on the mobile phone still reports the same error.
3. Modify the table Character Set utf8mb4:
Alter table UGC_REVIEW_CONTENT CHARSET = utf8mb4 COMMENT = 'Post/recommended comments ';
After the test, the app on the mobile phone still reports the same error.
4. Modify the character set utf8mb4 of the database:
Vim my. cnf
Init-connect = 'set NAMES utf8mb4'
Character-set-server = utf8mb4
Restart mysql database
[Root @ mysqlvm4 ~] # Service mysql restart
Shutting down MySQL... [OK]
Starting MySQL ...................................... ....... [OK] ..
[Root @ mysqlvm4 ~] #
View the character set of a Database
Mysql> show variables like '% char % ';
+ -------------------------- + ------------------------------------ +
| Variable_name | Value |
+ -------------------------- + ------------------------------------ +
| Character_set_client | utf8mb4 |
| Character_set_connection | utf8mb4 |
| Character_set_database | utf8mb4 |
| Character_set_filesystem | binary |
| Character_set_results | utf8mb4 |
| Character_set_server | utf8mb4 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/local/mysql/share/charsets/|
+ -------------------------- + ------------------------------------ +
8 rows in set (0.00 sec)
Mysql>
Recomment on the mobile app, enter the emoticon, and click Submit to indicate that the comment is successful.
5. Problem analysis summary:
(I) cause
The common string or expression occupies three bytes, so utf8 is enough, but the moving emoticon occupies four bytes, and the common utf8 is not enough, we recommend that you use the utf8mb4 character set in advance to cope with wireless internet opportunities and challenges, to avoid problems caused by emoji, and MySQL databases involving wireless data, this must be a key point of technology selection in the mobile Internet industry.
(Ii) Restrictions
Required> = MySQL 5.5.3 and slave database must also be 5.5. Earlier versions do not support this character set or duplicate error.
Reference Article address: http://bbs.csdn.net/topics/390055415
How can I hide the mysql database error message? Do not show it on the page
The birthday field is displayed in a date format.
The ada value is not wow.
Change 'ada 'to now ()
Mysql database creation error
Windos key + r enter services. msc to check if mysql service is enabled