//Modify YOUR_USERNAME and YOUR_PASSWORD. //drop table Hello if it exists in your database. // //Compile it by // javac oracle.java // //Run it by // java -cp .:$ORACLE_HOME/jdbc/lib/classes111.zip Hello // //See 8.5 in "A First Course in Database System", // Jeffrey D. Ullman and Jennifer Widom, Prentice Hall, 1997. import java.sql.*; //JDBC package class Hello { public static void main(String args[]) throws Exception // Bad programming style, please don't follow it. // Or you may lose marks for programming style. { //register oracle jdbc driver Class.forName("oracle.jdbc.driver.OracleDriver"); //connect to database Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@dbserv.dc.umd.edu:1521:SC424", "YOUR_USERNAME", "YOUR_PASSWORD"); //create a statment Statement stat = conn.createStatement(); //create table stat.executeUpdate("CREATE TABLE hello (value varchar(32))"); //insert data stat.executeUpdate("INSERT INTO hello VALUES('Hello world!')"); //query db ResultSet res = stat.executeQuery("SELECT * FROM hello "); if (res != null) for(; res.next();) System.out.println(res.getString(1)); res.close(); //close stat and conn stat.close(); conn.close(); } }