Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package model;
  2.  
  3. import control.ViewController;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.SQLException;
  7.  
  8. /**
  9.  * The connection to database, structured according to the singleton pattern
  10.  * with lazy initialization.
  11.  *
  12.  * @author Daniele Cuomo, Luca Gaudino, Mattia Formisano
  13.  */
  14.  
  15. public class DBConnection{
  16.     public final Connection conn;
  17.    
  18.     private DBConnection(){
  19.          String url = "jdbc:mysql://78.47.69.15/";
  20.         String db = "lgaudino_ingdb";
  21.         String usr = "lgaudino_ingu";
  22.         String pwd = "JECAJ3ANE53681K9";
  23.         Connection tmp = null;
  24.         try{
  25.             tmp = DriverManager.getConnection(url + db, usr, pwd);
  26.         }
  27.         catch (SQLException e){ ViewController.printErr(e); }
  28.         conn = tmp;
  29.     }    
  30.    
  31.     private static class Container{
  32.       private final static DBConnection INSTANCE = new DBConnection();
  33.     }
  34.  
  35.     /**
  36.      * Access point to connection
  37.      *
  38.      * @return the corresponding connection
  39.      */
  40.     public static DBConnection getInstance(){
  41.       return Container.INSTANCE;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement