//Modify YOUR_USERNAME and YOUR_PASSWORD. //Note that dbname is YOUR_USERNAME in PostgreSQL system. //drop table Hello if it exists in your database. // //Compile it by // javac *.java // //Download pg73jdbc3.jar, modify PATH_TO and run it by // java -cp .:PATH_TO/pg73jdbc3.jar Hello // //See 8.5 in "A First Course in Database System", // Jeffrey D. Ullman and Jennifer Widom, Prentice Hall, 1997. import java.sql.*; 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 driver and connect to db for PostgreSQL Class.forName("org.postgresql.Driver"); Connection connection = DriverManager.getConnection( "jdbc:postgresql://sql.csic.umd.edu/YOUR_USERNAME", "YOUR_USERNAME", "YOUR_PASSWROD"); //As expected, the following codes are as same as the codes for Oracle Statement statement = connection.createStatement(); statement.executeUpdate("CREATE TABLE hello (value varchar(32))"); statement.executeUpdate("INSERT INTO hello VALUES('Hello world!')"); ResultSet res = statement.executeQuery("SELECT * FROM hello "); if (res != null) for(; res.next();) System.out.println(res.getString(1)); res.close(); statement.close(); connection.close(); } }