package fuxi;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;
public class DBUtils {
public static final Properties pro=new Properties();
static{
InputStream is=DBUtils.class.getResourceAsStream("/db.properties");
try {
pro.load(is);
Class.forName(pro.getProperty("driver"));
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection connection=null;
try {
connection= DriverManager.getConnection(pro.getProperty("url"),pro.getProperty("user"), pro.getProperty("password"));
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
public static void closeAll(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet){
try {
if(resultSet!=null){
resultSet.close();
}
if (preparedStatement!=null){
preparedStatement.close();
}
if (connection!=null){
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}