/* */ import java.sql.DriverManager; import java.sql.Connection; import java.sql.SQLException; public class dbTest { public static void main(String args[]) { System.out.println("Check if Driver is registered with Driver Manager"); try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException cnfe) { System.out.println("Could NOT find the driver!"); System.exit(1); } System.out.println("we are so happy to have a registered driver, let's try to connect now..."); Connection c=null; try { // set the connection, user name, and password as needed c=DriverManager.getConnection("jdbc:postgresql://riogrande.cs.tcu.edu:5432/", "", ""); } catch (SQLException se) { System.out.println("Could NOT connect...we are so sad!"); System.exit(1); } if (c!=null) System.out.println("We are so happy to have made a connection to riogrande!"); else System.out.println("How did we ever get here??? Our code must be bad"); //NEED TO CLOSE OUR CONNECTION ALWAYS! try { //*************************************************************** c.close(); //**************************************************************** } catch (SQLException se) { System.out.println("ARGHH! Trouble closing down!"); System.exit(1); } //===================================================================== System.out.println("We are very please that all went well..."); } //end main } //end dbTest