首页 > 其他 > 详细

Data too long for column 'xxxx' at row 1 除了字段超长的另一种情况

时间:2019-09-06 18:39:54      阅读:115      评论:0      收藏:0      [点我收藏+]
{
 "result":null,
 "resultCode":"10001",
 "resultMsg":"\n### Error updating database.  Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column ‘xxxx‘ at row 1\n### The error may exist in class path resource [mapper/xxxx.xml]\n### The error may involve xxxxx.insertSelective-Inline\n### The error occurred while setting parameters\n### SQL: insert into xxxx  ( xxxx,  xxxx,  xxxx, xxxx
, xxxx, xxxx, xxxx ) values ( ?, ?, ?, ?, ?, ?, ? )\n### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column ‘xxxx‘ at row 1\n; ]; Data truncation: Data too long for column ‘xxxx‘ at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column ‘xxxx‘ at row 1" }

  今天代码里面报了一个这样的错误,Debug的时候取出这条SQL 和对应字段的数据  发现用Navicat 可以执行插入动作,然后很长的一段时间一直搞不定这个错误,因为字段映射正确,数据库中字段够长。

 

后来发现是同事在表中新增字段后,在修改 Mybatis的 映射xml文件时,insert into xxxx(column1,column2,column_add_1,column_add2,column3,column4) values (value1,value2,value_add_1,value_add2,value3,value4) 时 value_add_1,value_add2 两个新增列 位置写错了,写成了(value1,value2,value3,value4,value_add_1,value_add2)

这样一来,虽然在Java代码中 字段的内容是通过 bean 对应的字段传递到mybatis的映射文件中,但在执行插入动作时,字段匹配错误,导致原来很短的一个列,插入了很长的数据,所以报了  Data too long for column ‘xxxx‘ at row 1  这个错误。

 

中间浪费了两个小时没定位出来,这件是让我想到,我在定位错误的时候,应该仔细的看控制台打印的日志,而不能想当然的主观上肯定错误不会出现在某处,从而浪费时间。



 

Data too long for column 'xxxx' at row 1 除了字段超长的另一种情况

原文:https://www.cnblogs.com/cm-2019/p/11476870.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!