[英]Identify the failure of a executeBatch() in JDBC
I am using the following code to Insert data into a table. 我正在使用以下代码将数据插入表中。
test_conn.setAutoCommit(false);
stmt = test_conn.prepareStatement("INSERT INTO ...");
while(RSet.next()){
for(int i = 1; i <= columnCount; i++){
stmt.setString(i, RSet.getString(i));
}
stmt.addBatch();
}
stmt.executeBatch();
test_conn.commit();
other processing methods to occur only all the above rows are successfully inserted.... 仅将上述所有行成功插入的其他处理方法。
when I Insert into table using executeBatch()
, if an SQL Exception or Error occurs in Inserting , is it possible to find Insertion of which Record has thrown the exception? 当我使用
executeBatch()
插入表时,如果在插入过程中发生SQL异常或错误,是否可以找到哪个Record引发了异常的插入?
You have to try-catch
the stmt.executeBatch()
call and check for details in the exception. 您必须
try-catch
stmt.executeBatch()
调用,并检查异常中的详细信息。 Batch execution will stop on first error that will occure. 批处理将在发生第一个错误时停止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.