EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #99 background imageLoading...
Page #99 background image
Each ResultSet contains:
v If the ResultSet is not null, it contains the automatically generated keys
for an execution of the batched SQL statement.
v If the ResultSet is null, an error occurred during retrieval of the
automatically generated keys for the SQL statement.
3. Use SQLException methods getMessage, getSQLState, and getErrorCode to
retrieve the description of the error, the SQLSTATE, and the error code for the
first error.
4. Use the BatchUpdateException.getNextException method to get a chained
SQLException.
5. In a loop, execute the getMessage, getSQLState, getErrorCode, and
getNextException method calls to obtain information about an SQLException
and get the next SQLException.
The following code fragment demonstrates how to obtain the fields of a
BatchUpdateException and the chained SQLException objects for a batched
statement that returns automatically generated keys. The numbers to the right of
selected statements correspond to the previously-described steps.
try {
// Batch updates
} catch(BatchUpdateException buex) {
System.err.println("Contents of BatchUpdateException:");
System.err.println(" Update counts: ");
int [] updateCounts = buex.getUpdateCounts(); 1
for(inti=0;i<updateCounts.length; i++) {
System.err.println(" Statement"+i+":"+updateCounts[i]);
}
ResultSet[] resultList =
((DBBatchUpdateException)buex).getDBGeneratedKeys(); 2
for (i = 0; i < resultList.length(); i++)
{
if (resultList[i] == null)
continue; // Skip the ResultSet for which there was a failure
else {
java.math.BigDecimal idColVar = rs.getBigDecimal(1);
// Get automatically generated key
// value
System.out.println("Automatically generated key value="+idColVar);
}
}
System.err.println(" Message: " + buex.getMessage()); 3
System.err.println(" SQLSTATE: " + buex.getSQLState());
System.err.println(" Error code: " + buex.getErrorCode());
SQLException ex = buex.getNextException(); 4
while (ex != null) { 5
System.err.println("SQL exception:");
System.err.println(" Message: " + ex.getMessage());
System.err.println(" SQLSTATE: " + ex.getSQLState());
System.err.println(" Error code: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
Related tasks
“Making batch updates in JDBC applications” on page 28
Chapter 3. JDBC application programming 83
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability