Java Reference
In-Depth Information
con.setAutoCommit(true);
The DBMS executes the commands in the batch list in the order in which they are
added, returning an array of integer update counts.
The array of update counts represents the results of successfully executed
commands in the batch list in the order in which they are executed.
You will get a BatchUpdateException if any of the SQL statements in the batch do not
execute successfully.
Since the array of update counts represents the results of successfully executed
commands, you can easily identify the problem command from the length of the
returned array.
You should always disable auto -commit mode during a batch update so
that, if any errors occur, they can be handled properly. As shown in the
example, you need to issue a specific commit() command to commit the
updates.
Note
BatchUpdateException extends SQLException, adding an array of update counts
similar to the array the executeBatch method returns. You can retrieve this array
using the getUpdateCounts() method, as shown here:
try {
//...
} catch(BatchUpdateException b) {
System.err.print("Update counts: ");
int [] updateCounts = b.getUpdateCounts();
for (int i = 0; i < updateCounts.length; i++) {
System.err.println(updateCounts[i]);
}
}
Since the update counts are in the same order as the commands, you can tell which
commands in the batch have executed successfully.
Exception handling, SQLExceptions, and SQLWarnings are
discussed in more detail at the end of this chapter.
Cross-Reference
The results returned by a SQL query are held in a java.sql.ResultSet. This objects is
discussed in the next section .
ResultSets
Search WWH ::




Custom Search