mysql使用utf8mb4

插入mysql报错:

[ERROR] ### Error updating database.  Cause: java.sql.SQLException: Incorrect string value: '\xF3\xB2\xA5\xB7\xEF\xBF...' for column 'data' at row 1

[ERROR] ### The error may involve org.sonar.core.source.db.SnapshotSourceMapper.insert-Inline
[ERROR] ### The error occurred while setting parameters
[ERROR] ### SQL: insert into snapshot_sources (snapshot_id, data) values (?, ?)

[ERROR] ### Cause: java.sql.SQLException: Incorrect string value: '\xF3\xB2\xA5\xB7\xEF\xBF...' for column 'data' at row 1


如果字段是utf8,但是含有特殊字符如:微信表情,或者字节超过utf8的2个字节,就会以上错误:

  1. 更改字段utf8为utf8mb4(前提需要mysql版本5.5+才支持);
  2. web程序连接jdbc:mysql://10.153.122.139:3306/sonar?useUnicode=true&&characterEncoding=UTF-8,去掉&characterEncoding=UTF-8 ,变成 jdbc:mysql://10.153.122.139:3306/sonar?useUnicode=true即可。

你可能感兴趣的:(数据库mysql/oracle)