SHARE
TWEET

Untitled

a guest Jun 8th, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class DBConnect {
  2.    
  3.     private static final DBConnect instance = null;
  4.    
  5.     private static final String DRIVER = "com.mysql.jdbc.Driver";
  6.     private static final String BD_URL = "jdbc:mysql://"+
  7.             "localhost/customersdb";
  8.     private static final String USUARI = "customerjava";
  9.     private static final String PASSWORD = "customerjava";
  10.  
  11.     private DBConnect() throws ClassNotFoundException {
  12.         Class.forName(this.DRIVER);      
  13.     }
  14.    
  15.     /**
  16.      * implements singleton pattern.
  17.      * @return singleton instance of DBConnect class.
  18.      * @throws ClassNotFoundException if database api driver can not be loaded.
  19.      */
  20.     public static DBConnect getInstance() throws ClassNotFoundException {
  21.         if (instance == null) {
  22.             return new DBConnect();
  23.         }
  24.         else {
  25.             return instance;
  26.         }
  27.     }
  28.    
  29.     /**
  30.      *
  31.      * @return a connection
  32.      * @throws SQLException if a connection error occurs
  33.      */
  34.     public Connection getConnection() throws SQLException {
  35.         Connection conn=DriverManager.getConnection(BD_URL, USUARI, PASSWORD);
  36.         return conn;
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top