Trapping Exceptions in JDBC

Most errors that occur within a JDBC program can be trapped by using the exception handling capabilities provided by the Java programming language. This is done by using the try..catch statement block to catch the exception and the printStackTrace() method to print the stack trace.

The basic syntax to handle an exception is as follows:

Try {<code to execute>}
Catch(SQLException e){ e.printStackTrace(); }

The following is a code snippet from JdbcDml.java:

 public void dbConnection() { try { m_JdbcGui.putStatus("Connecting to the Database….please wait….."); //Register the JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); m_connection = DriverManager.getConnection( "jdbc:oracle:thin:@"+ ...

Get e-Commerce Applications Using Oracle8i and Java from Scratch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.