java.sql.SQLException
class extends the general java.lang.Exception
class that provides extra information about a database error.
Each SQLException
provides several kinds of information:
getMessage
.
SQLstate
conventions or the SQL99 conventions.
|
try { String database = "65.52.222.73:1521/cdb1"; OracleDataSource ods = new OracleDataSource( ); ods.setURL ( "jdbc:oracle:thin:@" + database ); ods.setUser ( "C##user.id" ); ods.setPassword( args[0].trim( ) ); Connection conn = ods.getConnection( ); System.out.println( "Successfully connect to Oracle.\n" ); Statement stmt = conn.createStatement( ); String cmd = "select * from " + args[1].trim( ); System.out.println( cmd + "\n" ); ResultSet rset = stmt.executeQuery( cmd ); // Iterate through the result and print the employees. while ( rset.next( ) ) System.out.println ( rset.getInt( 1 ) + " " + rset.getString( 2 ) ); } catch( SQLException ex ) { ex.printStackTrace( ); while ( ( ex = ex.getNextException( ) ) != null ) // while more exceptions ex.printStackTrace( ); } |
SQLWarning
provides information on database access warnings.
Warnings are silently chained to the object whose method caused it to be reported.
A car hit an elderly man. The paramedic says, “Are you comfortable?” The man says, “I make a good living.” |