Java Reference
In-Depth Information
System.err.println("ErrorCode: "+e.getErrorCode());
System.err.println("SQLState: "+e.getSQLState());
System.err.println("Message: "+e.getMessage());
System.err.println("NextException: "+e.getNextException());
e.printStackTrace(errLog);
System.err.println();
}
try{
stderr.close ();
}
catch (Exception e){
System.out.println("Redirection error: Unable to close SystemErr.txt");
}
}
}
A practical point worth noting is that the example saves current time and the current
thread as part of the logged-error information.
Caution
Remember to open your error-logging file for append. Otherwise, you
see only the last error. Also, it is a good idea to set autoFlush = true as
shown, so that errors are written to the file immediately.
This query is used in Listing 4-11 :
String query = "SELECT Name,Description,Qty,Cost,Sell_Price FROM Stock";
This query attempts to SELECT a nonexistent column, so a SQL Exception is thrown,
resulting in logging the following error messages to the error log:
Sun Dec 30 14:43:44 EST 2001
Thread: Thread[main,5,main]
ErrorCode: -3010
SQLState: 07001
Message: [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 1.
NextException: null
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few
parameters. Expected 1.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:2494)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:314)
at
Search WWH ::




Custom Search