Information Provided in SQLExceptions
Information Provided in SQLExceptions
Derby provides the message, SQLState values, and error codes. Use the getSQLState and getMessage methods to view the SQLState and error messages. Use getErrorCode to see the error code. The error code defines the severity of the error and is not unique to each exception. The severity levels are described inorg.apache.derby.types.ExceptionSeverity.
In addition, a single error can generate more than one SQLException. Use a loop and the getNextException method to process all SQLExceptions in the chain. In many cases, the second exception in the chain is the pertinent one.
catch (Throwable e) { System.out.println("exception thrown:"); errorPrint(e); } static void errorPrint(Throwable e) { if (e instanceof SQLException) SQLExceptionPrint((SQLException)e); else System.out.println("A non-SQL error: " + e.toString()); } static void SQLExceptionPrint(SQLException sqle) { while (sqle != null) { System.out.println("\n---SQLException Caught---\n"); System.out.println("SQLState: " + (sqle).getSQLState()); System.out.println("Severity: " + (sqle).getErrorCode()); System.out.println("Message: " + (sqle).getMessage()); sqle.printStackTrace(); sqle = sqle.getNextException(); } }
See also "Derby Exception Messages and SQL States", in the Derby Reference Manual.
Applications should also check for and process java.sql.SQLWarnings, which are processed in a similar way. Derby issues an SQLWarning if the create=true attribute is specified and the database already exists.
Previous Page
Next Page
Table of Contents
Index