Code: Select all
public class DbUtils {
private static Connection conn = null;
static {
final String DB_URL = "jdbc:mysql://localhost:3306/library";
final String USER = "root";
final String PASS = "12345";
try {
conn = DriverManager.getConnection(DB_URL, USER, PASS);
} catch (SQLException e) {
throw new RuntimeException(e);
}
System.out.println("Connected to database");
}
public static Connection getConnection() {
return conn;
}
}