// --------------------- import java.sql.*; // ----------------------- import java.util.*; import java.io.*; import java.lang.*; public class JDBCTest { private static Connection conn; private static int target = 1; ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////CREATE CONNECTION/////////////////////// public static void main(String args[]) { try{ Class.forName("oracle.jdbc.OracleDriver"); } catch (Exception ex) { System.out.println("Driver not found"); }; String url = "jdbc:oracle:thin:@hercules.csc.calpoly.edu:1522:ora10g"; conn = null; try { conn = DriverManager.getConnection(url, "name", "password"); } catch (Exception ex) { System.out.println("Could not open connection"); }; System.out.println("Connected"); try { Statement s1 = conn.createStatement(); String table = "CREATE TABLE Books "; table = table + "(LibCode INT, Title CHAR(50), Author CHAR(50),"; table = table + "PRIMARY KEY (LibCode) )"; System.out.println(table); s1.executeUpdate(table); } catch (Exception ee) {System.out.println(ee);} try { Statement s2 = conn.createStatement(); s2.executeUpdate("INSERT INTO Books VALUES(1, 'Database Systems','Ullman')"); s2.executeUpdate("INSERT INTO Books VALUES(2, 'Artificial Intelligence', 'Russel, Norvig')"); } catch (Exception ee) {System.out.println(ee);} try { Statement s3 = conn.createStatement(); ResultSet result = s3.executeQuery("SELECT Title FROM Books"); boolean f = result.next(); while (f) { String s = result.getString(1); System.out.println(s); f=result.next(); } s3.executeUpdate("DROP TABLE Books"); } catch (Exception ee) {System.out.println(ee);} try { conn.close(); } catch (Exception ex) { System.out.println("Unable to close connection"); }; } }