package com.mhys.utils;
import java.sql.*;
/**
* 数据库工具类
* @author Administrator
* 4321
*/
public class DBUtil {
private static final String DriverName="com.mysql.jdbc.Driver";
private static final String Url="jdbc:mysql://127.0.0.1:3306/book1";
private static final String User="root";
private static final String Pwd="123456";
static{
try {
Class.forName(DriverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConn() throws SQLException{
return DriverManager.getConnection(Url, User, Pwd);
}
public static void close(ResultSet rs,PreparedStatement ps,Connection conn){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(ps!=null){
try {
ps.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}