Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. package net.ironfight.official;
  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 url, host, database, user, pass;
  11.  
  12. public SQLConnection(String url, String host, String database, String user, String pass) {
  13. this.url = url;
  14. this.host = host;
  15. this.database = database;
  16. this.user = user;
  17. this.pass = pass;
  18. }
  19.  
  20. public void connection() {
  21. if(!isConnected()) {
  22. try {
  23. connection = DriverManager.getConnection(url + host + "/" + database + user + pass);
  24. System.out.println("La base de donnée MySQL à bien été connecté");
  25. } catch (SQLException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. }
  30.  
  31. public void disconnect() {
  32. if(isConnected()) {
  33. try {
  34. connection.close();
  35. System.out.println("La base de donnée MySQL à bien été fermé");
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. }
  41.  
  42. public boolean isConnected() {
  43. return connection != null;
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement