Skip to main content

Posts

Showing posts from February, 2009

Getting warnings from JDBC Connection

Sometimes it is a wise decision to retrieve the first warning reported by calls on this Connection object. This can be done using getWarnings() method. The code sample below shows how to print all the warnings with their sates and messages. Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ) ; Connection conn = DriverManager.getConnection( "jdbc:odbc:Database" ) ; // Print all warnings for( SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning() ) { System.out.println( "SQL Warning:" ) ; System.out.println( "State : " + warn.getSQLState() ) ; System.out.println( "Message: " + warn.getMessage() ) ; System.out.println( "Error : " + warn.getErrorCode() ) ; }