我正在使用 ibatis-sqlmap-2.3.0 版本并且需要在表中插入大约 70K 行。
使用 SqlExecutor Batch 功能我还想知道在 executeBatch() 中间失败的语句索引;
以下是相同的代码片段。
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
try {
for (TableRow ar1 : AllRows) {
executor.insert("myRates.insertData", ar1);
}
aBatchList = executor.executeBatchDetailed();
} catch (BatchException e) {
e.printStackTrace();
System.out.println("failing exception " + e.getFailingSqlStatement());
System.out.println("failing statement id " + e.getFailingStatementId());
System.out.println("message exception is " + e.getMessage());
System.out.println(e.getSuccessfulBatchResults());
}
}
问题:当失败结果出现时,它给了我重复数据的错误消息“om.ibatis.sqlmap.engine.execution.BatchException:子批次编号1失败”。
索引 1 是错误的,因为我知道重复条目位于其他行。
原因:我检查了这个 jar 的代码,它只考虑由我所有的 executor.insert("ratesUtil.insertAreaData", ar1); 组成的单个语句。
因此索引为 1。
输出供您参考:
1) System.out.println("失败异常" + e.getFailingSqlStatement()); --insert into table values (?,?,?) 2)System.out.println("failing statement id " + e.getFailingStatementId()); 3)System.out.println("消息异常为" + e.getMessage()); --子批号 1 失败。4)System.out.println(e.getSuccessfulBatchResults()); - 无效的
请帮助我 1)如何将这些插入查询设置为单个执行器中的多个批处理语句,并在单个 executor.executeBatch() 中执行所有这些批处理语句;
2)有没有其他方法来获得失败语句的正确索引。
我无法根据项目配置的一些问题更改版本。也不想依赖 updateCount 。