数据库问题之“字符编码问题 Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x8E\x81\xE7\x88...' for column 'product_name' at row 41”

发布时间 2023-07-04 20:51:46作者: 骚哥

 

1)表1和表2的产品名称[数据库字段]字符编译方式不一致

①问题

 

org.springframework.jdbc.UncategorizedSQLException:

Error updating database. Cause: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x8E\x81\xE7\x88...' for column 'product_name' at row 41

The error may involve com.bessky.financial.mapper.business.financereport.systemanalyze.AccountSkuShipmentRefundMapper.insertOrUpdateBatch-Inline

The error occurred while setting parameters

; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\x9F\x8E\x81\xE7\x88...' for column 'product_name' at row 41; nested exception is java.sql.SQLException: Incorrect string value: '\xF0\x9F\x8E\x81\xE7\x88...' for column 'product_name' at row 41

②原因

产品表和账号&sku退款率发货月的产品名称[数据库字段]字符编译方式不一致

  • 表1是:utf8mb4

 

  • 表2是:utf8

 

 

 

③解决思路

修改表2的产品名称字段字符集以及排序规则

因为这里表2是接收方,数据主要是从表1写入到这个表2中的

④解决方案

ALTER TABLE `account_sku` 
MODIFY COLUMN `product_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '产品名称';