package org.greenstone.gsdl3.gs3build.database; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class GS3SQLConnectionFactory { public static Connection getConnection(String database) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/"+database+"?user=gsdl3admin"/*&password=greenstone"*/); return connection; } catch (SQLException sqlEx) { System.out.println(sqlEx.toString()); } catch (Exception ex) { System.out.println(ex.toString()); return null; } return null; } public static SQLConnection getSQLConnection(String database) { Connection c = getConnection(database); if (c== null) { return null; } return new SQLConnection(c, database); } public static GS3SQLConnection getGS3SQLConnection(String database) { Connection c = getConnection(database); if (c== null) { return null; } return new GS3SQLConnection(c, database); } /* returns a Connection to the server, */ public static Connection getConnection() { return getConnection("test"); } /* returns a Connection to the server, */ public static SQLConnection getSQLConnection() { return getSQLConnection("test"); } public static GS3SQLConnection getGS3SQLConnection() { return getGS3SQLConnection("test"); } public static void main(String args[]) { GS3SQLConnection connection = getGS3SQLConnection(); connection.initCollection("maya"); } }