package zuoye;

import java.sql.*;

public class zuoye {
private static final String use="root";
private static final String pws="root";
private static final String ul="jdbc:mysql:///a";
private static final String s="com.mysql.jdbc.Driver";
//注册驱动
static{
try {
Class.forName(s);
} catch (Exception e) {
e.printStackTrace();
}
}
//连接数据库
public static Connection getConnection() throws Exception {
return DriverManager.getConnection(ul,use,pws);
}
//关闭资源
public static void a(Connection conn, Statement stat){
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stat!=null){
try {
stat.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static void a(Connection conn, Statement stat, ResultSet re){
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stat!=null){
try {
stat.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(re!=null){
try {
re.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
posted on 2019-04-02 08:29  ~王~  阅读(104)  评论(0编辑  收藏  举报