import java.io.*; import java.sql.*; /** * This class is to be used from all other classes to create the database connection. */ public class MyConnection { static String connectString = "jdbc:mysql://127.0.0.1/Catalog_G?user=root&password=platinium00"; static Connection instance; /** * Closes a connection. */ 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; } }