1. 程式人生 > >mysql存表情出錯的解決方案(類似xF0x9Fx98x86xF0x9F)

mysql存表情出錯的解決方案(類似xF0x9Fx98x86xF0x9F)

cau use 結果 column 之前 involve 成功 tail _proto_

之前以為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,測試成功

技術分享圖片

下面是修改後遊戲中的效果已經可以正常顯示表情了

技術分享圖片

mysql存表情出錯的解決方案(類似\xF0\x9F\x98\x86\xF0\x9F)