forked from giannisal/j0ar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basi.java
49 lines (34 loc) · 1.06 KB
/
Basi.java
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
package teamjava;
import java.sql.*;
public class Basi {
private final String dbname = "ismgroup77";
private final String dbusername = "ismgroup77";
private final String dbpassword = "rx673g";
private Connection con = null;
public Basi() {
}
public Connection getConnection() {
return this.con;
}
public void open() throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception e) {
throw new SQLException("MySQL Driver error: " + e.getMessage());
}
try {
con = DriverManager.getConnection("jdbc:mysql://195.251.249.131:3306/" + dbname, dbusername, dbpassword);
} catch (Exception e) {
con = null;
throw new SQLException("Could not establish connection with the Database Server: " + e.getMessage());
}
} // End of open
public void close() throws SQLException {
try {
if (con != null)
con.close();
} catch (Exception e) {
throw new SQLException("Could not close connection with the Database Server: " + e.getMessage());
}
}
}