sql语句:
insert INTO dt_pv_modules (
COMPANY_ID,
MODULE_ID,
PARENT_ID,
NAV_LEVEL,
FILE_NAME,
MODULE_LABEL,
MODULE_LABEL_EN,
DAP_CONTROLLED,
DEFAULT_DAP,
MODULE_HINT,
VALID_VERSION,
MUST_UPDATED,
IS_INACTIVE
) VALUES(
?,?,?,?,?,?,?,?,?,?,?,?,?)
on duplicate key update
COMPANY_ID = values(COMPANY_ID),
MODULE_ID = values(MODULE_ID),
PARENT_ID = values(PARENT_ID),
NAV_LEVEL = values(NAV_LEVEL),
FILE_NAME = values(FILE_NAME),
MODULE_LABEL = values(MODULE_LABEL),
MODULE_LABEL_EN = values(MODULE_LABEL_EN),
DAP_CONTROLLED = values(DAP_CONTROLLED),
DEFAULT_DAP = values(DEFAULT_DAP),
MODULE_HINT = values(MODULE_HINT),
VALID_VERSION = values(VALID_VERSION),
MUST_UPDATED = values(MUST_UPDATED),
IS_INACTIVE = values(IS_INACTIVE);
我是这么调用: result = Db.batch(sql, columns, changeList, changeList.size()); 如果 changeList.size() == 1就会正常执行 如果 changeList.size() > 1就会报下面的错误 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( 4000,80260025,80270000,null,'pcbaReturnLine','返回产线','Return to Produ' at line 31 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 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:1052) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2683) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2444) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2347) at com.mysql.jdbc.PreparedStatement.executeBatchedInserts(PreparedStatement.java:1789) ... 43 more 特别的当changeList.size() > 1,我直接打印出每个具体的sql语句,把他们直接放到客户端 逐条执行,发现都是没有错误的,也就是子语句没有生成错误,所以感到非常疑惑这个问题
项目:JFinal
例如 sql 中用到的参数个数,paras 要的数量要正确,是不是允许为 null 值等问题要处理好
此外,通过你的异常来看,是主键重复了
jfinal 的这个 batch 方法仅仅是将你的 sql + paras 直接扔给了 JDBC,自身并没有干预过这个过程,确保 sql 与 paras 是正确就好