Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public class DBConnect {
  2.  
  3. private static Connection conn;
  4. private static String url = "jdbc:mysql://localhost/company";
  5. private static String user = "root";
  6. private static String pass = "root";
  7.  
  8. public Connection connect() throws SQLException{
  9. try{
  10. Class.forName("com.mysql.jdbc.Driver").newInstance();
  11. }catch(ClassNotFoundException cnfe){
  12. System.err.println("Erreur: "+cnfe.getMessage());
  13. }catch(InstantiationException ie){
  14. System.err.println("Erreur: "+ie.getMessage());
  15. }catch(IllegalAccessException iae){
  16. System.err.println("Erreur: "+iae.getMessage());
  17. }
  18. conn = DriverManager.getConnection(url,user,pass);
  19. return conn;
  20. }
  21. public Connection getConnection() throws SQLException, ClassNotFoundException{
  22. if(conn !=null && !conn.isClosed())
  23. return conn;
  24. connect();
  25. return conn;
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement