forked from HelloWorld521/Java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDBUtils.java
More file actions
42 lines (41 loc) · 1005 Bytes
/
DBUtils.java
File metadata and controls
42 lines (41 loc) · 1005 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
package com.briup.common;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @author Chen
* jdbc连接数据库简单封住
* */
public class DBUtils{
private static Connection connection=null;
private static String driverName;
/**
* 获取Connection对象
* */
public static Connection getConnection(String url,String user,String password){
try {
driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
connection=
DriverManager.getConnection(url,user,password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
/**
* 关闭资源
* */
public static void close(ResultSet set,Statement statement,Connection conn){
try {
if(set!=null) set.close();
if(statement!=null) statement.close();
if(conn!=null)conn.close();
} catch (Exception e) {
}
}
}