日期:2014-05-19  浏览次数:20655 次

Data truncation: Data truncated for column 'sqDate' at row 1求高手解惑!
public void testCreateBatch(){
List<WyGame> wygameList = new ArrayList<WyGame>();
for(int i = 1;i<11;i++){
WyGame wygame = new WyGame();
wygame.setGameName("xxxxxxxx");
wygame.setXlhType("xxxxxxxx");
wygame.setIsUsed("false");
String xlh = "xxxxxxxxxxxxx";
wygame.setXlh(xlh+i);
wygame.setSqDate(new Date());
wygameList.add(wygame);
}
wygameservice.createBatch(wygameList);
}
执行这个方法会报:
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update; SQL [insert into mychat.wygame (gameName, xlhType, xlh, sqDate, isUsed, id) values (?, ?, ?, ?, ?, ?)]; Data truncation: Data truncated for column 'sqDate' at row 1; nested exception is java.sql.BatchUpdateException: Data truncation: Data truncated for column 'sqDate' at row 1 这个错误
能成功插入第一条记录,只是之后9条记录没有插入数据库,数据库sqDate字段的类型为date;
求高手解惑,如何解决这个问题。

------解决方案--------------------
先只插入一条试试,如果还抱着个错的话,应该可以断定数据长度有问题,看看数据库这个字段的类型和长度是什么,再看看程序中这个字段值长度多少,调试一下,应该很简单
------解决方案--------------------
关键得看createBatch里的写法。。。
------解决方案--------------------
sqDate字段写入数据出错了,sqDate是定义为什么类型的数据啊。
------解决方案--------------------
日期类型插入的时候要这样

2012-09-12 14:29:04

你得格式化一下

具体什么格式 就看你的要求了、

yyyy-MM-dd HH:mm:ss

用 SimpleDateFormat这个
------解决方案--------------------
“Data truncated for column 'sqDate' at row 1” 指数据被截断了啊,对象中设置的时间格式是带时分秒的啊,数据库data类型数据不会带时分秒啊。 这个也去数据库有关的,像mysql就不会提示错误。