[8741] | 1 | package org.greenstone.gsdl3.gs3build.database;
|
---|
| 2 |
|
---|
| 3 | import java.sql.Connection;
|
---|
| 4 | import java.sql.DriverManager;
|
---|
| 5 | import java.sql.SQLException;
|
---|
| 6 |
|
---|
[8745] | 7 |
|
---|
[8741] | 8 | public class GS3SQLConnectionFactory
|
---|
| 9 | {
|
---|
[8745] | 10 | public static Connection getConnection(String database)
|
---|
[8741] | 11 | {
|
---|
| 12 | try {
|
---|
| 13 | Class.forName("com.mysql.jdbc.Driver").newInstance();
|
---|
| 14 |
|
---|
| 15 | Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/"+database+"?user=gsdl3admin"/*&password=greenstone"*/);
|
---|
| 16 | return connection;
|
---|
| 17 | }
|
---|
| 18 | catch (SQLException sqlEx)
|
---|
| 19 | { System.out.println(sqlEx.toString());
|
---|
| 20 | }
|
---|
| 21 | catch (Exception ex)
|
---|
| 22 | { System.out.println(ex.toString());
|
---|
| 23 | return null;
|
---|
| 24 | }
|
---|
| 25 | return null;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
[8745] | 28 | public static SQLConnection getSQLConnection(String database)
|
---|
| 29 | {
|
---|
| 30 | Connection c = getConnection(database);
|
---|
| 31 | if (c== null) {
|
---|
| 32 | return null;
|
---|
| 33 | }
|
---|
[9874] | 34 | return new SQLConnection(c, database);
|
---|
[8741] | 35 | }
|
---|
| 36 |
|
---|
[8745] | 37 |
|
---|
| 38 | public static GS3SQLConnection getGS3SQLConnection(String database)
|
---|
| 39 | {
|
---|
| 40 | Connection c = getConnection(database);
|
---|
| 41 | if (c== null) {
|
---|
| 42 | return null;
|
---|
| 43 | }
|
---|
[9874] | 44 | return new GS3SQLConnection(c, database);
|
---|
[8741] | 45 | }
|
---|
| 46 |
|
---|
[8745] | 47 | /* returns a Connection to the server, */
|
---|
| 48 | public static Connection getConnection()
|
---|
| 49 | {
|
---|
| 50 | return getConnection("test");
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | /* returns a Connection to the server, */
|
---|
| 54 | public static SQLConnection getSQLConnection()
|
---|
| 55 | {
|
---|
| 56 | return getSQLConnection("test");
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | public static GS3SQLConnection getGS3SQLConnection()
|
---|
| 60 | {
|
---|
| 61 | return getGS3SQLConnection("test");
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[8741] | 64 | public static void main(String args[])
|
---|
[8745] | 65 | {
|
---|
| 66 | GS3SQLConnection connection = getGS3SQLConnection();
|
---|
| 67 | connection.initCollection("maya");
|
---|
[8741] | 68 | }
|
---|
| 69 | }
|
---|