1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.finalist.util.genelv.db;
19
20 import java.sql.*;
21 import java.util.*;
22 import java.io.*;
23 import java.net.*;
24
25 import org.apache.log4j.Category;
26
27 /***
28 * This class does the lookup for the database table to locate the error code / error type mapping
29 *
30 * @author Gerard van de Weerd
31 * @created 19 april 2002
32 */
33 public class GenElvConnectionManager implements Serializable {
34 static Category log = Category.getInstance(GenElvConnectionManager.class);
35
36 static private GenElvConnectionManager instance;
37
38 static String MY_SQL_DRIVER_CLASS = "org.gjt.mm.mysql.Driver";
39 static String DB_URL = "jdbc:mysql://192.168.0.60/genelv";
40 static String DB_USER = "genelv";
41 static String DB_PASSWORD = "genelv";
42
43
44 /***
45 * Default constructor. Loads my sql driver class;
46 */
47 protected GenElvConnectionManager() throws ClassNotFoundException {
48 Class.forName(MY_SQL_DRIVER_CLASS);
49 }
50
51
52 /***
53 *
54 */
55 static public GenElvConnectionManager getInstance() throws SQLException {
56 System.out.println("GenElvConnectionManager getInstance()");
57 if (instance == null) {
58 try {
59 instance = new GenElvConnectionManager();
60 }
61 catch (ClassNotFoundException e) {
62 e.printStackTrace();
63 instance = null;
64 throw new SQLException("Class " + MY_SQL_DRIVER_CLASS + " cannot be found.");
65 }
66 }
67 return instance;
68 }
69
70
71 /***
72 *
73 */
74 protected Connection getConnection() throws SQLException {
75 try {
76 Class.forName(MY_SQL_DRIVER_CLASS);
77 }
78 catch (Exception e) {
79 }
80 return DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
81 }
82
83
84 /***
85 * Create return connection calling methode is responsable for closing
86 * this connection
87 * @throws SQLException When the lookup failed or if there is no database
88 * @return The Connection
89 */
90 static public Connection connect() throws SQLException {
91 return getInstance().getConnection();
92 }
93
94 }