Handling SQL errors in an SQLj application
SQLj clauses use the JDBC class
 java.sql.SQLException
 for error handling. 
SQLj generates an SQLException under the following circumstances:
When any SQL statement returns a negative SQL error code 
When a SELECT INTO SQL statement returns a +100 SQL error code 
You can use the 
getErrorCode
 method to retrieve SQL error codes and the 
getSQLState
 method to retrieve SQLSTATEs.
To handle SQL errors in your SQLj application, import the 
java.sql.SQLException 
class, and use the Java error handling try/catch blocks to modify program flow 
when an SQL error occurs (see Example 7 51).
Example 7 51   SQL Exception with SQLj
try {
  #sql [ctxt] {SELECT LASTNAME INTO :empname
    FROM EMPLOYEE WHERE EMPNO= 000010 };
}
catch(SQLException e) {
  System.out.println("Error code returned: " + e.getErrorCode());
}
For exception handling in Java it is important to know that DB2 provides several 
types of JDBC drivers
with slightly different characteristics. With the DB2 
Universal JDBC Driver, you can retrieve the SQLCA. For the DB2 JDBC type 2 
driver for Linux, UNIX, and Windows (DB2 JDBC type 2 driver), use the standard 
SQLException to retrieve SQL error information.
SQLException under the DB2 Universal JDBC Driver
As in all Java programs, error handling is done using try/catch blocks. Methods 
throw exceptions when an error occurs, and the code in the catch block handles 
those exceptions.
JDBC provides the 
SQLException
 class for handling errors. All JDBC methods 
throw an instance of SQLException when an error occurs during their execution. 
According to the JDBC specification, an SQLException object contains the 
following information:
A string object that contains a description of the error or null 
A string object that contains the SQLSTATE or null 
An int value that contains an error code 
A pointer to the next SQLException or null 
The DB2 Universal JDBC Driver provides an extension to the SQLException 
class, which gives you more information about errors that occur when DB2 is 
216 
MySQL to DB2 UDB Conversion Guide






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

san diego web hosting

 

Our partners: PHP: Hypertext Preprocessor Cheap Web Hosting JSP Web Hosting Ontario Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Java Hosting Cheapest Hosting

Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved