Tuesday 20 December 2016

SQLException

With the help of exception handling we can take the appropriate action in case something goes wrong like committing the data or rolling it back etc. JDBC execute statement or connection related exception throws SQLException which is a checked Exception

SQLException

SQLException class is available in java.sql package and extends Exception class which means all methods that we used to use in Exception will be available in SQLException also. There are other relevant methods added in SQLException class which we will discuss in this section.
SQLException Useful methods:
                There are several methods available but below are the most commonly used methods.
1.   int getErrorCode()-  this method can be used to get the vendor-specific exception or error code.


2.   SQLException getNextException()- This method is used to get the chained exception which is being set using  setNextException(SQLException ex) method.


3.   Iterator iterator()-  This method is used to iterate all the chained exceptions in SQL Exception.


4.   void setNextException(SQLException ex)- This method is used to add another SQL exception in chain.
5.   String getSQLState() – This method is used to retrieve the SQLState for SQLException object. This method can return null as well.

0 comments:

Post a Comment

Powered by Blogger.

Stats