【发布时间】:2016-01-06 04:31:16
【问题描述】:
我正在尝试使用PreparedStatement.executeBatch() 执行批处理查询并尝试捕获BatchUpdateException 中发生的任何异常。但是我在调用BatchUpdateException.getUpdateCounts() 时得到一个空白数组。
下面是我的代码:
int[] updateCounts = null;
PreparedStatement stmt = null;
// some logic to set the stmt and create the SQL query
try {
if (count % 100 == 0)
{
updateCounts = stmt.executeBatch();
}
} catch (BatchUpdateException bu)
{
updateCounts = bu.getUpdateCounts();
}
当异常发生时,我得到一个空数组updateCounts...为什么?
注意:
BatchUpdateException -
SystemErr R java.sql.BatchUpdateException: ORA-01400: 不能 将 NULL 插入 ("TABLE_ABC"."AMOUNT")
代码从中读取数据的 CSV 文件...预计第三条记录中出现错误
Asof_Date,Price_Date,Amount
12/15/2015,11/26/2014,-2646.937686
12/15/2015,11/28/2014,5053.611471
12/15/2015,1/22/2015,
12/15/2015,1/23/2015,
【问题讨论】:
-
空数组是指长度为0的数组吗?如果是这样,那么很可能是因为您实际上并没有在批次中添加任何东西,例如
count为 0。 -
打印异常可能会提供一些见解
-
@Andreas - 它有 11 条记录,即计数为 11
标签: java oracle jdbc prepared-statement