工具类连接数据库 JDBCUtils: package cn.pzhu.util;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.*;
public class JDBCUtils {
private static String driver = null;
private static String url = null;
private static String user = null;
private static String password = null;
private Connection con;
private PreparedStatement preparedStatement;
private ResultSet resultSet;
//1.注册驱动
static{
InputStream in = JDBCUtil.class.getClassLoader().getResourceAsStream("db.properties");
Properties properties = new Properties();
try {
properties.load(in);
driver = properties.getProperty("driver");
url = properties.getProperty("url");
user = properties.getProperty("user");
password = properties.getProperty("password");
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public JDBCUtils(){
try {
con=DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
e.printStackTrace();
}
}
//2.获得连接
public Connection getConnection(){
return con;
}
//3.释放资源
public static void close(Connection connection, Statement statement, ResultSet result){
if(result!=null){
try {
result.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if(connection!=null){
try {
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
} if(statement!=null){
try {
statement.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
public boolean updateSql(String sql, List