package com.util.www;
import java.sql.*;
public class DBUtil {
//获取数据库连接
public Connection getConn(){
Connection conn=null;
try {
//加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//获取连接
conn=DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;databaseName=qlzx","sa","123456"
);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
//关闭数据库服务连接
public void closeConn(ResultSet rs,PreparedStatement ps,Connection conn){
try{
//判断并关闭
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
if(conn!=null){
conn.close();
}
}catch(SQLException e){
e.printStackTrace();
}
}
}