/* ** +-----------------------------------------------+ ** | FILE : TestThinConnection.java | ** | AUTHOR : Jeff Hunter | ** | DATE : 06-DEC-2001 | ** +-----------------------------------------------+ */ import java.sql.*; class TestThinConnection { static final String query_string = "select 'Current Date/Time : ' || " + "TO_CHAR(sysdate, 'DD-MON-YYYY HH24:MI:SS') " + "from dual"; public static void main (String args[]) throws SQLException { Connection conn = null; Statement stmt = null; ResultSet rset = null; try { System.out.print("\n"); System.out.print("+-------------------------------+\n"); System.out.print("| SETUP CONNECTION |\n"); System.out.print("+-------------------------------+\n"); System.out.print("\n"); /* ** CONNECT TO THE DATABASE */ conn = OracleConnection.getConnection(); /* ** EXECUTE GENERIC QUERY */ System.out.print("\n"); System.out.print("+-------------------------------+\n"); System.out.print("| EXECUTE GENERIC QUERY |\n"); System.out.print("+-------------------------------+\n"); System.out.print("\n"); System.out.print("Executing Generic (SYSDATE) Query...\n"); System.out.print("Creating Statement...\n"); stmt = conn.createStatement (); System.out.print("Opening ResultsSet...\n"); rset = stmt.executeQuery (query_string); while (rset.next ()) { System.out.print(" RESULTS -> " + rset.getString (1) + "\n"); } System.out.print("Closing ResultSet...\n"); rset.close(); System.out.print("Closing Statement...\n"); stmt.close(); } // TRY: catch (SQLException e) { if (conn != null) { try {conn.rollback();} catch (SQLException e1) {e1.printStackTrace();} } e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null) { try { System.out.print("\n"); System.out.print("+-------------------------------+\n"); System.out.print("| CLOSE DOWN ALL CONNECTIONS |\n"); System.out.print("+-------------------------------+\n"); System.out.print("\n"); System.out.print("Closing down all connections...\n\n"); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } // FINALLY: } // METHOD: (main) } // CLASS: (TestThinConnection)