-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDbConn.java
More file actions
47 lines (39 loc) · 1006 Bytes
/
DbConn.java
File metadata and controls
47 lines (39 loc) · 1006 Bytes
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
package com.ddbs.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import javax.print.DocFlavor.STRING;
public class DbConn {
public Connection getConn(){
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/bookshop?useUnicode=true&characterEncoding=utf-8";
String username = "root";
String password = "cpprootmysql";
return DriverManager.getConnection(url,username,password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public void close(Statement sta,Connection conn){
try {
sta.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void close(PreparedStatement sta,Connection conn){
try {
sta.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}