JDBC exception handling is done using the try-catch block of the Java application. A DB2 application throws an SQLException whenever it encounters the SQL error while running the SQL statements.
An object of SQLException is created and thrown whenever an error occurs while accessing the database.The object gives the following information regarding the error:
Apart from the above information, DB2 JCC driver provides an extra interface com. ibm. db2. jcc. DB2Diagnosable. This interface gives more information regarding the error that occurred while accessing the DB2 database. DB2Diagnosable interface has the following methods:
If multiple SQLExceptions are thrown, they are chained. The next exception information can be retrieved by calling the getNextException method of the current SQLException object. This method will return null if the current SQLException object is last in the chain. A while loop in the catch block of the program can be used to retrieve all the SQLException objects one by one. Below example shows how to handle the SQLException in the try-catch block.
The SQLException class has multiple subclasses, which define more specific errors. We explain these classes next.
The SQLWarning object is created whenever there is a database warning that occurred while calling the methods of the following classes:
All these interfaces contain the getWarning method to retrieve the warning information. Note that the creation SQLWarning object does not throw any SQLException. You need to call the getWarning method of the above interface to check if any warning exists or not.
Handling SQL warning
The DataTruncation class is a subclass of the SQLWarning to handle the data truncation whenever an application tries to insert a value larger than the value defined in the database definition. In that case, the data is stored after truncating the value to the specified size and a DataTruncation object is created to provide the information. Whenever truncation happens while reading the value from the database, an SQLWarning object is created instead of DataTruncation. A DataTruncation object is created when truncation occurred during writing to the database.
All the methods in SQLException and SQLWarning classes are inherited in this class. Apart from these, the following methods give more information regarding DataTruncation Exception:
An object of BatchUpdateException is thrown whenever an error occurs while running a set of statements together by using BatchUpdate. This class inherits all the methods from java.lang.Exception class. Apart from that, the following method is provided by the Batch Update Exception for the additional information:
IBM DB2 Related Interview Questions
|IBM Websphere Interview Questions||IBM-REXX Interview Questions|
|IBM Cognos Interview Questions||IBM DB2 Interview Questions|
|J2EE Interview Questions||COBOL Interview Questions|
|IBM-JCL Interview Questions||DB2 Using SQL Interview Questions|
|IBM WAS Administration Interview Questions||IBM WebSphere Administration Interview Questions|
|Database Administration Interview Questions||DB2 SQL Programming Interview Questions|
|Mainframe DB2 Interview Questions|
IBM DB2 Related Practice Tests
|IBM Websphere Practice Tests||IBM Cognos Practice Tests|
|IBM DB2 Practice Tests||J2EE Practice Tests|
|COBOL Practice Tests||IBM-JCL Practice Tests|
|DB2 Using SQL Practice Tests||IBM WAS Administration Practice Tests|
|Database Administration Practice Tests||DB2 SQL Programming Practice Tests|
Ibm Db2 Tutorial
Db2 Application Development Overview
Application Development With Db2 Purexml
Application Development With Php
Application Development With C/c++
Application Development With Java
Application Development With .net
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.