1 | package org.greenstone.gsdl3.gs3build.database;
|
---|
2 |
|
---|
3 | import java.sql.Connection;
|
---|
4 | import java.sql.DriverManager;
|
---|
5 | import java.sql.SQLException;
|
---|
6 |
|
---|
7 |
|
---|
8 | public class GS3SQLConnectionFactory
|
---|
9 | {
|
---|
10 | public static Connection getConnection(String database)
|
---|
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 |
|
---|
28 | public static SQLConnection getSQLConnection(String database)
|
---|
29 | {
|
---|
30 | Connection c = getConnection(database);
|
---|
31 | if (c== null) {
|
---|
32 | return null;
|
---|
33 | }
|
---|
34 | return new SQLConnection(c);
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | public static GS3SQLConnection getGS3SQLConnection(String database)
|
---|
39 | {
|
---|
40 | Connection c = getConnection(database);
|
---|
41 | if (c== null) {
|
---|
42 | return null;
|
---|
43 | }
|
---|
44 | return new GS3SQLConnection(c);
|
---|
45 | }
|
---|
46 |
|
---|
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 |
|
---|
64 | public static void main(String args[])
|
---|
65 | {
|
---|
66 | GS3SQLConnection connection = getGS3SQLConnection();
|
---|
67 | connection.initCollection("maya");
|
---|
68 | }
|
---|
69 | }
|
---|