Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package fr.toundrake.faveur;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class SQLConnection {
  8.  
  9. private Connection connection;
  10. private String urlbase, sQLHost, sQLName, sQLUser, sQLPass;
  11.  
  12. public SQLConnection(String urlbase, String sQLHost, String sQLName, String sQLUser, String sQLPass) {
  13. this.urlbase = urlbase;
  14. this.sQLHost = sQLHost;
  15. this.sQLName = sQLName;
  16. this.sQLUser = sQLUser;
  17. this.sQLPass = sQLPass;
  18. }
  19.  
  20. public void connect(){
  21. if(!isConnected()){
  22. try {
  23. System.out.println(urlbase + sQLHost + "/" + sQLName + sQLUser + sQLPass);
  24. connection = DriverManager.getConnection(urlbase + sQLHost + "/" + sQLName, sQLUser, sQLPass);
  25. System.out.println("Connection effectuée");
  26. } catch (SQLException e) {
  27. // TODO Auto-generated catch block
  28. e.printStackTrace();
  29. System.out.println("arf, il y a un problème de connexion à la base SQL");
  30. }
  31. }
  32. }
  33.  
  34. public void disconnect(){
  35. if(isConnected()){
  36. try {
  37. connection.close();
  38. System.out.println("Déconnexion effectuée");
  39. } catch (SQLException e) {
  40. // TODO Auto-generated catch block
  41. e.printStackTrace();
  42. }
  43. }
  44. }
  45.  
  46. public boolean isConnected(){
  47. return connection != null;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement