-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataBaseConnectionMgr.java
More file actions
executable file
·42 lines (32 loc) · 1.04 KB
/
Copy pathDataBaseConnectionMgr.java
File metadata and controls
executable file
·42 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Apply Singleton pattern for handling the connection to the database
@author: Jesus Cuenca
*/
public class DataBaseConnectionMgr{
private static String driver;
private static String database;
private static String user;
private static String password;
private static FCDriver fcdriver=null;
protected DataBaseConnectionMgr(){
}
public static synchronized FCDriver getFCDriver() throws Exception{
if(fcdriver == null){
if ( (driver == null) || (database == null) || (user == null) || (password == null)){
throw new Exception("No connection parameters");
}
if(driver.equals("org.postgresql.Driver")){
PostgresqlDriverConnection c=new PostgresqlDriverConnection();
c.connect(database,user,password);
fcdriver=c;
}
}
return fcdriver;
}
public static void setConnectionParameters(String driver,String database,String user, String password){
DataBaseConnectionMgr.driver=driver;
DataBaseConnectionMgr.database=database;
DataBaseConnectionMgr.user=user;
DataBaseConnectionMgr.password=password;
}
}