Java Reference
In-Depth Information
int getErrorCode() returns a vendor-specific integer error code.
Normallythisvaluewillbetheactualerrorcodereturnedbytheunderlyingdata
source.
SQLException getNextException() returnsthe SQLException in-
stancechainedtothis SQLException object(viaacallto setNextExcep-
tion(SQLException ex) ), or null when there isn't a chained exception.
String getSQLState() returns a “SQLstate” string that provides an
X/Open or SQL:2003 error code identifying the exception.
Iterator<Throwable> iterator() returns an iterator over the
chained SQLException s and their causes in proper order. The iterator will
beusedtoiterateovereach SQLException anditsunderlyingcause(ifany).
Youwouldnormally notcall this method, butwouldinstead usethe enhanced
for statement (discussed in Chapter 5 ), which calls iterator() , when you
need to iterate over the chain of SQLException s.
void setNextException(SQLException sqlex) appends sqlex
to the end of the chain.
Oneormore SQLException smightoccurwhileprocessingarequest,andthecode
that throws these exceptions can add them to a chain of SQLException s by invok-
ing setNextException() .Also,an SQLException instancemightbethrownas
aresultofadifferentexception(e.g., IOException ),whichisknownasthatexcep-
tion's cause (see Chapter 3 ) .
SQLstateerrorcodesaredefinedbytheISO/ANSIandOpenGroup(X/Open)SQL
standards.Theerrorcodeisa5-characterstringconsistingofa2-characterclassvalue
followed by a 3-character subclass value. Class value “00"”indicates success, class
value “01”indicates awarning,andotherclass values normally indicate anexception.
ExamplesofSQLstateerrorcodesare00000(success)and08001(unabletoconnectto
the data source).
Thefollowingexampleshowsyouhowyoumightstructureyourapplicationtomake
a connection to a Java DB data source, perform some work, and respond to a thrown
SQLException instance:
String url = "jdbc:derby:employee;create=true";
try (Connection con = DriverManager.getConnection(url))
{
// Perform useful work. The following throw statement
simulates a
// JDBC method throwing SQLException.
Search WWH ::




Custom Search