Java Reference
In-Depth Information
The SQLWarning class extends SQLException to provide information on
database-access warnings. Warnings are silently chained to the object whose
method causes the warning to be reported and are returned by the getWarnings()
method of that class.
In addition to the inherited methods of SQLException, SQLWarning provides methods
to get the next SQLWarning for additional information or to add a warning to the
chain.
BatchUpdateException
A BatchUpdateException provides information about problems arising during batch
updates. BatchUpdateException extends SQLException, adding an array of update
counts similar to the array returned by the executeBatch method. You can retrieve
this array by using the getUpdateCounts() method as follows:
int [] updateCounts = b.getUpdateCounts();
Since the update counts are in the same order as the commands, you can tell which
commands in the batch have executed successfully.
Logging
In all but the simplest applications, it is worth incorporating some degree of error and
event logging. The most basic form of logging, of course, is the use of System.err and
System.out to report exceptions and significant events.
In a practical application, simply dumping exception messages to the system console
is generally inadequate. It is preferable to use dedicated logging files or perhaps even
a database to manage event logs and error logs.
It is easy to implement a file-based error and event-logging system by simply
redirecting the basic System.err stream and by defining a PrintWriter for use by the
Exception class for dumping a StackTrace.
Listing 4-11 extends the example of Listing 4-1 to demonstrate two different ways to
log exceptions to an error-logging file:
 
Define a PrintWriter for use with the printStackTrace() method.
 
Redirect System.err to a logging file by using System.setErr().
Listing 4-11: Logging errors to a file
package java_databases.ch04;
import java.io.*;
Search WWH ::




Custom Search