-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbUtil.java
More file actions
64 lines (38 loc) · 910 Bytes
/
Copy pathDbUtil.java
File metadata and controls
64 lines (38 loc) · 910 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.kinggm.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
/*
* 数据库工具类
*/
public class DbUtil {
//数据库地址
private String dbUrl = "jdbc:mysql://localhost:3306/db_book";
//用户名
private String dbUserName = "root";
//密码
private String dbPassword = "123456";
//驱动名称
private String jdbcName = "com.mysql.jdbc.Driver";
// 获取数据库连接
public Connection getCon() throws Exception {
Class.forName(jdbcName);
Connection con = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
return con;
}
// 关闭数据库连接
public void closeCon(Statement smt ,Connection con) throws Exception {
if (smt != null) {
smt.close();
}
if (con != null) {
con.close();
}
}
// 关闭数据库连接
public void closeCon(Connection con) throws Exception {
if (con != null) {
con.close();
}
}
}