source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnectionFactory.java@ 8745

Last change on this file since 8745 was 8745, checked in by kjdon, 19 years ago

reorganised the GS3SQLConnection and connectionFactory. now have a base connection class, SQLCOnnection, which does general connection stuff, while GS3SQLConnection extends this, and does collection specific stuff. methods in the factory have been renamed - can now ask for a Connection, SQLCOnnection or GS3SQLConnection.

  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1package org.greenstone.gsdl3.gs3build.database;
2
3import java.sql.Connection;
4import java.sql.DriverManager;
5import java.sql.SQLException;
6
7
8public 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}
Note: See TracBrowser for help on using the repository browser.