Role of Exceptions in JDBC

In JSE API, java.sql package comes under JDBC. When we observe this package, every method in this package throws an SQLException. That means the successful working of these method is based on user. In order to overcome this problem user should write error less code. Since every method throws an exception it is recommended to handle the exception instead of throwing them.

        That means instead of using throws SQLException , we should write try and catch blocks. The following is the realtime code where we handle exceptions:

Exceptions in JDBC
Fig: Realtime code of JDBC
In the above program we are declaring the Connection,Statement and ResultSet variables before the try block, because if we declare them inside try block they are invisible to finally block and gives exception. 

    

    

No comments:

Post a Comment