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 #98 background imageLoading...
Page #98 background image
Related concepts
“Example of a simple JDBC application” on page 7
Related tasks
“Handling an SQLException under the IBM Data Server Driver for JDBC and
SQLJ” on page 77
Retrieving information from a BatchUpdateException
When an error occurs during execution of a statement in a batch, processing
continues. However, executeBatch throws a BatchUpdateException.
To retrieve information from the BatchUpdateException, follow these steps:
1. Use the BatchUpdateException.getUpdateCounts method to determine the
number of rows that each SQL statement in the batch updated before the
exception was thrown.
getUpdateCount returns an array with an element for each statement in the
batch. An element has one of the following values:
n The number of rows that the statement updated.
Statement.SUCCESS_NO_INFO
This value is returned if the number of updated rows cannot be
determined.
Statement.EXECUTE_FAILED
This value is returned if the statement did not execute successfully.
2. If the batched statement can return automatically generated keys:
a. Cast the BatchUpdateException to a
com.ibm.db2.jcc.DBBatchUpdateException.
b. Call the DBBatchUpdateException.getDBGeneratedKeys method to retrieve an
array of ResultSet objects that contains the automatically generated keys for
each execution of the batched SQL statement.
c. Test whether each ResultSet in the array is null.
String url = "jdbc:db2://myhost:9999/myDB:" + 1
"retrieveMessagesFromServerOnGetMessage=true;";
// Set properties to retrieve full message
// text
String user = "db2adm";
String password = "db2adm";
java.sql.Connection con =
java.sql.DriverManager.getConnection (url, user, password)
// Connect to a DB2 for z/OS data source
Statement stmt;
ResultSet rs;
SQLWarning sqlwarn;
...
stmt = con.createStatement(); // Create a Statement object
rs = stmt.executeQuery("SELECT * FROM EMPLOYEE");
// Get the result table from the query
sqlwarn = stmt.getWarnings(); // Get any warnings generated 2
while (sqlwarn != null) { // While there are warnings, get and 3a
// print warning information
System.out.println ("Warning description: " + sqlwarn.getMessage()); 3b
System.out.println ("SQLSTATE: " + sqlwarn.getSQLState()); 3c
System.out.println ("Error code: " + sqlwarn.getErrorCode()); 3d
sqlwarn=sqlwarn.getNextWarning(); // Get next SQLWarning 3f
}
Figure 26. Example of processing an SQLWarning
82 Application Programming Guide and Reference for Java
|
|
|
|
|
|
|

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