Class.forName("oracle.jdbc.driver.OracleDriver");
// or you can use:
// DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =
DriverManager.getConnection(
"jdbc:oracle:thin:@dssw2k01:1521:orcl","scott","tiger");
System.out.println("Connection opened.");
String sql =
"select 'Hello Thin driver tester '||USER||'!' result from xdual";
Statement stmt = null;
ResultSet rset = null;
try {
stmt = conn.createStatement();
rset = stmt.executeQuery(sql);
while(rset.next())
System.out.println(rset.getString(1));
rset.close();
rset = null;
stmt.close();
stmt = null;
}
catch (SQLException e) {
System.err.println("SQLException: " + e.getMessage().trim());
System.err.println("in HandlingSQLExceptions while executing: ");
System.err.println(sql);
}
finally {
if (rset != null) try { rset.close(); } catch (SQLException ignore) { }
if (stmt != null) try { stmt.close(); } catch (SQLException ignore) { }
}
conn.close();
System.out.println("Connection closed.");