Ibatis的SqlExecutor类里:
public int executeBatch() throws SQLException {
int totalRowCount = 0;
for (int i = 0, n = statementList.size(); i < n; i++) {
PreparedStatement ps = (PreparedStatement) statementList.get(i);
int[] rowCounts = ps.executeBatch();
for (int j = 0; j < rowCounts.length; j++) {
if (rowCounts[j] == Statement.SUCCESS_NO_INFO) {
// do nothing
} else if (rowCounts[j] == Statement.EXECUTE_FAILED) {
throw new SQLException("The batched statement at index " + j + " failed to execute.");
} else {
totalRowCount += rowCounts[j];
}
}
}
return totalRowCount;
}
StatementList是存放sql命令的。
这段代码对于oracle的驱动,int[] rowCounts = ps.executeBatch();这段代码返回的永远是[-2,-2],而 Statement.SUCCESS_NO_INFO值也为-2.所以最后批处理的结果返回的影响记录数就是0了。参考:
即ibatis+oracle的驱动对于批处理返回的结果一直是0.ibatis说是oracle的驱动的bug,但是hibernate+oracle时设置一个参数就能拿到批处理影响的记录数了。参考:http://blog.csdn.net/elimago/article/details/1676516 这个我没有试过,如果真是这样,ibatis是不是也可以自己修改代码也做到这样呢@ibatis.