Advertisement
Guest User

Untitled

a guest
May 1st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package DataBase;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.SQLException;
  11.  
  12. /**
  13. *
  14. * @author Olfa Karoui
  15. */
  16. public class MyConnexion {
  17.  
  18. private String url = "jdbc:mysql://localhost:3306/pi";
  19. private String login = "root";
  20. private String pwd ="";
  21. private Connection con;
  22. private static MyConnexion instance = null;
  23.  
  24. private MyConnexion() {
  25. try
  26. {
  27. con = DriverManager.getConnection(url, login, pwd);
  28. System.out.println("connexion ok");
  29. } catch (SQLException ex)
  30. {
  31. System.out.println("NOT OK");
  32. }
  33. }
  34. public static MyConnexion getInstance()
  35. {
  36. if(instance == null)
  37. {
  38. instance = new MyConnexion();
  39. }
  40. return instance;
  41. }
  42.  
  43. public Connection getCon() {
  44. return con;
  45. }
  46.  
  47.  
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement