Advertisement
Guest User

Untitled

a guest
May 9th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 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 td7;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.SQLException;
  11.  
  12. /**
  13. *
  14. * @author usersio
  15. */
  16. public class DAOConnexion {
  17. // Attributs
  18. private static Connection connexion = null;
  19. private static final String URL = "jdbc:mysql://localhost:3306/home_v0";
  20. private static final String USER = "userapp";
  21. private static final String MDP = "pwapp";
  22.  
  23. // Constructeur
  24. private DAOConnexion(){
  25. }
  26. // Getteur
  27. public static Connection getConnexion(){
  28. if (null==DAOConnexion.connexion){
  29. DAOConnexion.setConnexion();
  30. }
  31. return DAOConnexion.connexion;
  32. }
  33. // Setteur
  34. private static void setConnexion(){
  35. try {
  36. DAOConnexion.connexion = DriverManager.getConnection(DAOConnexion.URL, DAOConnexion.USER, DAOConnexion.MDP);
  37. }
  38. catch (SQLException e){
  39. System.out.println("td7.DAOConnexion.setConnexion()"+" : Problème de connexion à la bdd!");
  40. }
  41. }
  42.  
  43. // Autres
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement