db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@debrunners.com>
Subject Re: Running for the first time
Date Fri, 13 May 2005 03:11:44 GMT
Paul J. Lucas wrote:

>     Also, if it's not too much trouble, I'm new to using JDBC so I'm
>     wondering how SQLWarnings are caught.  They're derived from
>     SQLException, but does that mean that SQLWarnings are thrown and
>     must be caught using a try/catch block?  Or are warnings caught
>     some other way?

SQLWarnings are not thrown, even though they are a sub-class of
Exception. I guess you should see that as an implementation detail.

Various JDBC objects have getWarnings() methods in their interfaces,
like Connection, Statement and ResultSet. You need to call these methods
after an operation and see if any warnings exist. Null is returned for
no warnings. Eg. call conn.getWarnings() after creating a Connection.

A word of warning :-), SQLWarnings and SQLExceptions are chained using
getNextWarning and getNextException. For Derby the most information is
obtained when the full chain is displayed, in some situations the actual
cause of an error can be several levels down in the exception chain.


  for (SQLWarning sw = rs.getWarnings(); sw != null; sw =
      System.out.println(sw.getSQLState() + " " + sw.getMessage());


View raw message