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 org.apache.log4j.Category;
21
22 import java.io.Serializable;
23 import java.sql.Connection;
24 import java.sql.DriverManager;
25 import java.sql.SQLException;
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 ConnectionManager implements Serializable {
34 static Category log = Category.getInstance(ConnectionManager.class);
35
36 static private ConnectionManager instance;
37
38 static String DRIVER_CLASS = "oracle.jdbc.driver.OracleDriver";
39 static String DB_URL = "jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
40 static String DB_USER = "USERNAME";
41 static String DB_PASSWORD = "PASSWORD";
42
43
44 /***
45 * Default constructor. Loads my sql driver class;
46 */
47 protected ConnectionManager() throws ClassNotFoundException {
48 Class.forName(DRIVER_CLASS);
49 }
50
51
52 /***
53 *
54 */
55 static public ConnectionManager getInstance() throws SQLException {
56 System.out.println("ConnectionManager getInstance()");
57 if (instance == null) {
58 try {
59 instance = new ConnectionManager();
60 }
61 catch (ClassNotFoundException e) {
62 e.printStackTrace();
63 instance = null;
64 throw new SQLException("Class " + 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(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 }