-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyConnect.java
More file actions
56 lines (46 loc) · 1.28 KB
/
Copy pathMyConnect.java
File metadata and controls
56 lines (46 loc) · 1.28 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
package com.company;
import org.postgresql.util.PSQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MyConnect {
private MyConnect(){}
static MyConnect base = null;
public static MyConnect instance() {
if (base == null) {
base = new MyConnect();
}
return base;
}
public boolean connect(){
String URL = "jdbc:postgresql://127.0.0.1:5432/testB";
try {
conn = DriverManager.getConnection(URL, userCur.getName(), userCur.getPass());
} catch (PSQLException e) {
System.out.println("Connection Failed! Check output console");
return true;
} catch (SQLException e) {
}
return false;
}
public void close(){
try {
conn.close();
}
catch (SQLException e){
System.out.println("error: connect.close()");
}
}
public Connection getConn() {
return conn;
}
public MyUser getName() {
return userCur;
}
public static void setUserCur(MyUser userCur) {
MyConnect.userCur = userCur;
}
private String name = "";
private Connection conn = null;
private static MyUser userCur = new MyUser();
}