package Utils;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
public class Utils {
private static String user;
private static String pwd;
private static String driver;
private static String url;
static {
try {
Properties properties = new Properties();
properties.load(new FileInputStream("src\mysql.properties"));
user = properties.getProperty("user");
pwd = properties.getProperty("password");
driver = properties.getProperty("driver");
url = properties.getProperty("url");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Connection connection(){
try {
Class.forName(driver);
return DriverManager.getConnection(url,user,pwd);
} catch (ClassNotFoundException | SQLException e) {
throw new RuntimeException(e);
}
}
public static void close(ResultSet set,Statement statement,Connection connection){
try {
if(set!=null){
set.close();
}
if (statement!=null){
statement.close();
}
if(connection!=null){
connection.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}