mysql存表情出错的解决方案(类似\xF0\x9F\x98\x86\xF0\x9F)
之前以为mysql设置utf-8以及昵称decode后就万事大吉了,结果最近才发现对于4字节的表情会报错。
报错信息如下:
data: null
message: " ### Error updating database. Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x86\xF0\x9F...' for column 'nickName' at row 1 ### The error may involve com.smallfoxdog.demo.mapper.UserMapper.insertUser-Inline ### The error occurred while setting parameters ### SQL: insert into users(id,wxOpenid,nickName,avatarUrl,gender,province,city,country,continue_days) values(NULL,?,?,?,?,?,?,?,1) ### Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x86\xF0\x9F...' for column 'nickName' at row 1 ; uncategorized SQLException; SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\x9F\x98\x86\xF0\x9F...' for column 'nickName' at row 1; nested exception is java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x86\xF0\x9F...' for column 'nickName' at row 1"
status: 200
timestamp: 1526283581431
__proto__: Object
errMsg: "request:ok"
header: Object
解决方案:https://blog.csdn.net/yown/article/details/52627223(注:他里面有2个sql我执行失败,但是一样也改好了)
但是看其他帖子说数据库连接的时候去掉编码格式,目前我的链接地址如下,去掉了characterEncoding=utf8,测试成功
下面是修改后游戏中的效果已经可以正常显示表情了