-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.java
49 lines (30 loc) · 1.02 KB
/
database.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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class database {
public ResultSet accessDB (String query){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch(Exception e1 ){
}
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1/surgery?user=root&password=");
stmt = conn.createStatement();
stmt.execute(query); {
rs = stmt.getResultSet();
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
return rs;
}
}