今天在运行程序插入数据库时,出现了如下的bug:

org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [replace into task_result values(?,?,?,?)]; SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\xBF\xAA\xB7\xEF\xBF...' for column 'ip_info' at row 1; nested exception is java.sql.SQLException: Incorrect string value: '\xF0\xBF\xAA\xB7\xEF\xBF...' for column 'ip_info' at row 1。

网上百度了一下,是Emoji字符导致的。

虽然我修改了mysql的默认字符集为utf8,但是为3个字节,存储Emoji字符需要4个字节的utfm8。修改my.cnf。

修改前:

mysql错误SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\xBF\xAA\xB7\xEF\xBF...'

修改字符集:

mysql错误SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\xBF\xAA\xB7\xEF\xBF...'

修改后再次查看字符。

mysql错误SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\xBF\xAA\xB7\xEF\xBF...'


相关文章:

  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2021-05-09
  • 2022-12-23
  • 2021-11-03
  • 2022-12-23
  • 2021-05-11
猜你喜欢
  • 2021-07-27
  • 2022-12-23
  • 2021-06-29
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
相关资源
相似解决方案