Advertisement
haikelfazzani

Connection DB MYSQL + Singleton

Dec 24th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. package utilitaire;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class ConnectionDB {
  8.    
  9.     private static Connection connection;
  10.    
  11.     static {
  12.        
  13.         try {
  14.            
  15.             Class.forName("com.mysql.jdbc.Driver");
  16.             connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test" , "root" , "");
  17.            
  18.         } catch (ClassNotFoundException | SQLException e) {
  19.             throw new RuntimeException("not connected " ,e);
  20.         }
  21.     }
  22.    
  23.     public static Connection getConnection() {
  24.         return connection;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement