2017年4月20日 | Leave a comment 问题: iphone 输入法有很多表情,如果使用utf8保存到数据库会报错, Internal Exception: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x94\xA5' for column 'result' at row 1 1 Internal Exception: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x94\xA5' for column 'result' at row 1 所以需要支持utf8mb4 解决: 修改mysql服务器中的 my.cnf 中 character_set_server = ‘utf8mb4’ & collation_server = ‘utf8mb4_unicode_ci’ 检查数据库、table 、 列是否都已经设置为utf8mb4 检查jdbc.connection url 是否已经设置为 characterSet=utf8 ;(不是utf8mb4,utf8会自动支持utf8mb4) 把所有charaset 设置为 utf8mb4 可以在Java程序中检查下下 SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%'; 1 SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%'; | 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 | | collation_connection | utf8mb4_unicode_ci | | collation_database | utf8mb4_unicode_ci | | collation_server | utf8mb4_unicode_ci | 12345678910 | 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 || collation_connection | utf8mb4_unicode_ci || collation_database | utf8mb4_unicode_ci || collation_server | utf8mb4_unicode_ci | 参考: http://www.tuicool.com/articles/zAnEV3 http://blog.csdn.net/junsure2012/article/details/42171035