source: trunk/greenstone3-extensions/gs3build/src/org/greenstone/gsdl3/gs3build/database/GS3SQLConnectionFactory.java@ 12188

Last change on this file since 12188 was 12188, checked in by kjdon, 18 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1package org.greenstone.gsdl3.gs3build.database;
2
3import java.sql.Connection;
4import java.sql.DriverManager;
5import java.sql.SQLException;
6import java.io.InputStream;
7import java.util.Properties;
8import org.greenstone.gsdl3.util.GlobalProperties;
9
10public class GS3SQLConnectionFactory
11{
12
13 public static Connection getConnection(String database)
14 {
15 try {
16 String server = GlobalProperties.getProperty("mysql.server", "localhost");
17 String port = GlobalProperties.getProperty("mysql.tcp.port", "3306");
18 String password = GlobalProperties.getProperty("mysql.gsdl3admin.password");
19
20 Class.forName("com.mysql.jdbc.Driver").newInstance();
21 String connection_address = "jdbc:mysql://"+server+":"+port+"/"+database+"?user=gsdl3admin";
22 if (password != null && !password.equals("")) {
23 connection_address += "&password="+password;
24 }
25 Connection connection = DriverManager.getConnection(connection_address);
26 return connection;
27 }
28 catch (Exception ex) {
29 System.out.println("GS3SQLConnectionFactory.getConnection() Error:");
30 System.out.println(ex.getMessage());
31 }
32 return null;
33 }
34
35 public static SQLConnection getSQLConnection(String database)
36 {
37 Connection c = getConnection(database);
38 if (c== null) {
39 return null;
40 }
41 return new SQLConnection(c, database);
42 }
43
44
45 public static GS3SQLConnection getGS3SQLConnection(String database)
46 {
47 Connection c = getConnection(database);
48 if (c== null) {
49 return null;
50 }
51 return new GS3SQLConnection(c, database);
52 }
53
54 /* returns a Connection to the server, */
55 public static Connection getConnection()
56 {
57 return getConnection("test");
58 }
59
60 /* returns a Connection to the server, */
61 public static SQLConnection getSQLConnection()
62 {
63 return getSQLConnection("test");
64 }
65
66 public static GS3SQLConnection getGS3SQLConnection()
67 {
68 return getGS3SQLConnection("test");
69 }
70
71 public static void main(String args[])
72 {
73 GS3SQLConnection connection = getGS3SQLConnection();
74 connection.initCollection("maya");
75 }
76}
Note: See TracBrowser for help on using the repository browser.