Deal with JDBC Batch Update Results


Handle batch update results with following code snippet :

int[] numUpdates= stmt.executeBatch();


for (int i = 0; i < numUpdates.length; i++) {
if (numUpdates[i] >= 0) {
// Successfully executed; the number represents number of affected rows
System.out.println("OK: updateCount=" + numUpdates[i]);
} else if (numUpdates[i] == Statement.SUCCESS_NO_INFO) {
// Successfully executed; number of affected rows not available
System.out.println("OK: updateCount=Statement.SUCCESS_NO_INFO");
} else if (numUpdates[i] == Statement.EXECUTE_FAILED) {
System.out.println("updateCount=Statement.EXECUTE_FAILED");
}
}





Extra Info :

int java.sql.Statement.SUCCESS_NO_INFO = -2 [0xfffffffe]

The constant indicating that a batch statement executed successfully but that no count of the number of rows it affected is available.

int java.sql.Statement.EXECUTE_FAILED = -3 [0xfffffffd]

The constant indicating that an error occured while executing a batch statement.

Following is the good link for more info about Batch Updates :

http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Frzaha%2Fbatchstm.htm

0 nhận xét:

Đăng nhận xét