package com.dbcp;
import java.io.IOException;
import java.sql.*;
import java.util.*;
public class JDBCUtils {
private static Properties properties;
private static String url;
private static String driverClass;
private static String username;
private static String password;
private static Connection connection = null;
private static PreparedStatement pstmt ;
static {
properties = new Properties();
try {
// properties.load(new FileInputStream(new File("db.properties")));
properties.load(JDBCUtils.class.getResourceAsStream("db.properties"));
url = properties.getProperty("url");
driverClass = properties.getProperty("driverClass");
username = properties.getProperty("username");
password = properties.getProperty("password");
} catch (IOException e) {
e.printStackTrace();
}
}
//得到连接
public static Connection getConnection(){
try {
Class.forName(driverClass);
connection = DriverManager.getConnection(url,username,password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
//关闭所有连接
public static void closeAll(Connection conn, Statement statement, ResultSet resultSet){
try {
if (resultSet!=null){
resultSet.close();
}
if (conn!=null){
conn.close();
}
if (statement!=null){
statement.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
//增加,删除,修改
public static boolean updateByPreparedStatement(String sql, List