Handling errors and warnings in JDBC applications
A Java application uses its own way of catching exceptions. An error is commonly referred to as an exception in Java applications. An exception can be recognized by an exception class. A try block can have multiple catch blocks. The idea is to handle every possibility of the error condition. JDBC also provides some standard exception classes that can be used to capture the basic information. Apart from them, DB2 also provides its own exception classes that can be used for better diagnosis. In this recipe, we will focus on exception handling in Java applications.
Getting ready
JDBC applications use try and catch blocks to handle different exceptions. There is no exception thrown in the case of warnings. To handle warnings in JDBC applications, we need to explicitly check for warnings. We can use the getWarning()
method to retrieve warnings as a SQLWarning
object that has the following information:
Description of the warning
SQLSTATE
Error...