forked from maniero/SOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnection.java
More file actions
64 lines (52 loc) · 1.96 KB
/
Copy pathConnection.java
File metadata and controls
64 lines (52 loc) · 1.96 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
public abstract class GenericConnection {
private Connection conn;
private Statement st;
public Statement getSt() {
return st;
}
public void setSt(Statement st) {
this.st = st;
}
public Connection getConn() {
return conn;
}
public void setConn(Connection conn) {
this.conn = conn;
}
protected Properties dbProperties = new Properties();
public Properties getDbProperties() {
if (dbProperties == null) {
try {
dbProperties.load(new FileInputStream("src/properties/conf.properties"));
} catch (FileNotFoundException ex) {
Logger.getLogger(GenericConnection.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(GenericConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}
return dbProperties;
}
public void setDbProperties(Properties dbProperties) {
GenericConnection.dbProperties = dbProperties;
}
public Connection getConnection();
}
public class OracleConnection extends GenericConnection {
@Override
public Connection getConnection() {
if (getConn() != null) {
return getConn();
} else {
try {
String url = "jdbc:oracle:thin:@" + getDbProperties().getProperty("ServerOracle") + ":" + getDbProperties().getProperty("portOracle") + ":" + getDbProperties().getProperty("sidOracle");
setConn(DriverManager.getConnection(url, getDbProperties().getProperty("userOracle"), getDbProperties().getProperty("passwdOracle")));
setSt(getConn().createStatement());
return getConn();
} catch (SQLException ex) {
Logger.getLogger(OracleConnection.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
}
}
//https://pt.stackoverflow.com/q/142868/101