Database Reference
In-Depth Information
if ( e instanceof SQLException ) // JDBC-specific exception?
{
// e must be cast from Exception to SQLException to
// access the SQLException-specific methods
printException (( SQLException ) e );
}
}
finally
{
if ( conn != null )
{
try
{
conn . close ();
System . out . println ( "Disconnected" );
}
catch ( SQLException e )
{
printException ( e );
}
}
}
}
public static void tryQuery ( Connection conn )
{
try
{
// issue a simple query
Statement s = conn . createStatement ();
s . execute ( "USE cookbook" );
s . close ();
// print any accumulated warnings
SQLWarning w = conn . getWarnings ();
while ( w != null )
{
System . err . println ( "SQLWarning: " + w . getMessage ());
System . err . println ( "SQLState: " + w . getSQLState ());
System . err . println ( "Vendor code: " + w . getErrorCode ());
w = w . getNextWarning ();
}
}
catch ( SQLException e )
{
printException ( e );
}
}
public static void printException ( SQLException e )
{
// print general message, plus any database-specific message
Search WWH ::




Custom Search