Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package model;
- import control.ViewController;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- /**
- * The connection to database, structured according to the singleton pattern
- * with lazy initialization.
- *
- * @author Daniele Cuomo, Luca Gaudino, Mattia Formisano
- */
- public class DBConnection{
- public final Connection conn;
- private DBConnection(){
- String url = "jdbc:mysql://78.47.69.15/";
- String db = "lgaudino_ingdb";
- String usr = "lgaudino_ingu";
- String pwd = "JECAJ3ANE53681K9";
- Connection tmp = null;
- try{
- tmp = DriverManager.getConnection(url + db, usr, pwd);
- }
- catch (SQLException e){ ViewController.printErr(e); }
- conn = tmp;
- }
- private static class Container{
- private final static DBConnection INSTANCE = new DBConnection();
- }
- /**
- * Access point to connection
- *
- * @return the corresponding connection
- */
- public static DBConnection getInstance(){
- return Container.INSTANCE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement