Advertisement
Guest User

Untitled

a guest
Jul 14th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.  private String dbDriverName = "com.mysql.jdbc.Driver";
  2.     private String dburl = "jdbc:mysql://localhost:3306/marfa_ghelasdb";
  3.     private String dbuser = "ghelas_admin";
  4.     private String dbpassword = "1234";
  5.  
  6.     private Connection connection;
  7.  
  8.     private static MyDataSource instance;
  9.  
  10.     public static MyDataSource getInstance() {
  11.  
  12.         if (instance == null) {
  13.             instance = new MyDataSource();
  14.         }
  15.  
  16.         return instance;
  17.     }
  18.  
  19.     public Connection getConnection() throws SQLException {
  20.  
  21.         if (connection == null || (connection != null && connection.isClosed())) {
  22.             connection = DriverManager.getConnection(dburl, dbuser, dbpassword);
  23.         }
  24.  
  25.         return connection;
  26.     }
  27.     private void loadDriver() throws ClassNotFoundException {
  28.         Class.forName(dbDriverName); //incarcarea jar-ului care corespunde numelui dat in JVM
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement