//Modify YOUR_USERNAME and YOUR_PASSWORD. //drop table Hello if it exists in your database. // //Download classes12.zip, modify PATH_TO and compile it by // javac -classpath .:PATH_TO/classes12.zip oracle2.java // //Modify PATH_TO and run it by // java -cp .:PATH_TO/classes12.zip HelloAgain // //See 8.5 in "A First Course in Database System", // Jeffrey D. Ullman and Jennifer Widom, Prentice Hall, 1997. import java.sql.*; import javax.sql.*; //new JDBC package, supports DataSource import oracle.jdbc.pool.*; //Oracle driver class HelloAgain { public static void main(String args[]) throws Exception // Bad programming style, please don't follow it. // Or you may lose marks for programming style. { // Create a DataSource OracleDataSource source = new OracleDataSource(); source.setDataSourceName("Oracle"); source.setDriverType("thin"); source.setDatabaseName("SC424"); source.setPortNumber(1521); source.setServerName("dbserv.dc.umd.edu"); source.setUser("YOUR_USERNAME"); source.setPassword("YOUR_PASSWORD"); source.setNetworkProtocol("tcp"); //connect to database Connection conn = source.getConnection(); //create a statment Statement statement = conn.createStatement(); //create table statement.executeUpdate("CREATE TABLE hello (value varchar(32))"); //insert data statement.executeUpdate("INSERT INTO hello VALUES('Hello world again!')"); //query db ResultSet res = statement.executeQuery("SELECT * FROM hello "); if (res != null) for(; res.next();) System.out.println(res.getString(1)); res.close(); //close statement and conn statement.close(); conn.close(); } }