/* * DbConnect.java * * Created on December 7, 2004, 7:52 AM */ package uw.ischool.info340.labs; import javax.naming.*; import javax.sql.*; import java.sql.*; /* * The program demonstrates how to connect to a postgresql database * using JDBC. * * The following things must already be in place * * (1) * You must know the name of the machine that is running postgresql * (e.g., serv55.ischool.washington.edu) * The machine must up and postgress must be running. * * (2) * You must have a postgresql user ID and password and have been * assigned a database. * * (3) * You must have the following relation in the database * * Table "public.state" * Column | Type | Modifiers * --------+-----------------------+----------- * sname | character varying(40) | not null * scode | character(2) | not null * */ public class DbConnect { /* * This is the location/URL of the database. It conforms to this connection string: * jdbc:postgresql://:/ * * Notes: * a) team12 == is the name of the database * b) 5432 is the port number -- it is optional * c) serv55.ischool.washington.edu -- is the name of the host */ private static String cDB_URL_STRING = "jdbc:postgresql://linux.ischool.washington.edu:5432/dhendry"; /* * NOTE: Check that the user ID and password are correct * * To make the connection a UserID and password are required */ private static String cUserID = ""; private static String cUserPassword = "