/* * Code by George Kichukov for SAS 10/27/2002 * This class is to be used from all other classes to create the database connection. * use like this: * Connection conn=MyConnection.open(); * MyConnection.close(); */ package utilities; import java.io.*; import java.sql.*; public class MyConnection { //uses this string to connect to the MySQL Datatbase - Catalog_G //and passes usrname - sastest and the password static String connectString = "jdbc:mysql://localhost.localdomain/Catalog_G?user=sastest&password=Cat!lug"; static Connection instance; public static void close() { if(instance!=null) { try { instance.close(); } catch(SQLException e){System.err.println("SQLException " + e.getMessage());} } } //loads the MySQL jdbc driver and return a Connecton public static Connection open() { if(instance==null) { try { //Load the driver Class.forName("org.gjt.mm.mysql.Driver").newInstance(); instance = DriverManager.getConnection (connectString); } catch(SQLException e){System.err.println("SQLException " + e.getMessage());} catch(InstantiationException e){System.err.println("InstantException " + e.getMessage());} catch(ClassNotFoundException e){System.err.println("ClassNotFoundException " + e.getMessage());} catch(IllegalAccessException e){System.err.println("IllegalAccessException " + e.getMessage());} } return instance; } }