ShardingSphere修改报错-MysqlDataTruncation: Data truncation: Out of range value for column ‘xx‘ at row 1

在使用ShardingJDBC进行数据库操作时遇到错误,报错信息显示为MysqlDataTruncation,原因是表中的MSGID字段为int类型,但尝试插入的msgId值为String类型,导致数据溢出。解决方案包括修改表字段数据类型以匹配实体类属性,或者反之。
摘要由CSDN通过智能技术生成


一、场景

1、项目使用ShardingJDBC操作数据库

2、修改SQL执行报错


二、报错信息

### Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'MSGID' at row 1
### The error may involve com.xxx.mapper.service.KeyWordMapper.updateByExample-Inline
### The error occurred while setting parameters
### SQL: UPDATE t_wx_keyword  SET keyword = ?,msgType = ?,msgId = ?,content = ?,createTime = ?,eable = ?,matchType = ?,originId = ?,vdnId = ? WHERE (       (  vdnId = ?                                                and originId = ?                                                and id = ? ) )
### Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'MSGID' at row 1
; Data truncation: Out of range value for column 'MSGID' at row 1; nested exception is com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'MSGID' at row 1
org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'MSGID' at row 1
### The error may involve com.xxx.mapper.service.KeyWordMapper.updateByExample-Inline
### The error occurred while setting parameters
### SQL: UPDATE t_wx_keyword  SET keyword = ?,msgType = ?,msgId = ?,content = ?,createTime = ?,eable = ?,matchType = ?,originId = ?,vdnId = ? WHERE (       (  vdnId = ?                                                and originId = ?                                                and id = ? ) )
### Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'MSGID' at row 1
; Data truncation: Out of range value for column 'MSGID' at row 1; nested exception is com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'MSGID' at row 1

三、原因

表字段的数据类型与实体类属性的类型不一致

在本例中:表字段MSGID的数据类型是int,而实体类的msgId属性类型是String,类型不一致


四、解决

方法1、更改表字段数据类型,与实体类属性类型一致

方法2、更改实体类属性类型,与表字段数据类型一致

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值