问题产生的条件:
自定义硬SQL,batch方式insert时候,会多一条空的数据的数据。
发生问题的调用代码:
Sql sql = Sqls.create("insert into t_person (name,age) value (@name,@age)");
for (int i = 0 ; i < 10 ; i++){
sql.params().set("name",UUID.randomUUID());
sql.params().set("age", i);
sql.addBatch();
}
问题的详细说明:
如上个代码,跟代码进去,会发现 ParamMatrix 中多一条
null,null
的数值,导致整个事务出错,既无论执行多少条sql,最后一��
�会是 insert into t_person (name,age) value (null,null)
异常堆栈:
Exception in thread "main" org.nutz.dao.DaoException:
org.nutz.dao.DaoException: !Nutz SQL Error: 'insert into t_person (name,age)
value ('aad6a572-7216-4865-a93c-56b4fcce74d3',0)'
PreparedStatement:
'insert into t_person (name,age) value (?,?)'
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:74)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:178)
at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:169)
at com.weiyouxi.openplatform.dbcommon.App.main(App.java:64)
Caused by: org.nutz.dao.DaoException: !Nutz SQL Error: 'insert into t_person
(name,age) value ('aad6a572-7216-4865-a93c-56b4fcce74d3',0)'
PreparedStatement:
'insert into t_person (name,age) value (?,?)'
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:149)
at org.nutz.dao.impl.DaoSupport$2.invoke(DaoSupport.java:181)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:63)
... 3 more
Caused by: java.sql.BatchUpdateException: Column 'name' cannot be null
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2028)
at com.mysql.jdbc.PreparedStatement.executeBatchedInserts(PreparedStatement.java:1696)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1440)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:195)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:125)
... 5 more
Caused by:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
Column 'name' cannot be null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1039)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1980)
... 10 more
相关日志:
Original issue reported on code.google.com by lngjy12...@gmail.com on 11 Jan 2012 at 9:42
Original issue reported on code.google.com by
lngjy12...@gmail.com
on 11 Jan 2012 at 9:42