Guest User

Untitled

a guest
Aug 31st, 2016
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package fr.minefus.snyker.common.sql;
  2.  
  3. import fr.minefus.snyker.common.sql.table.MPlayer;
  4.  
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8.  
  9. /**
  10. * Created by Arkas on 31/08/2016.
  11. * @author Snyker
  12. */
  13. public class SQL {
  14.  
  15. private Connection connection;
  16. public MPlayer mPlayer;
  17. private String urlbase, host, database, user, pass;
  18.  
  19. public SQL(){
  20. this.urlbase = "jdbc:mysql://";
  21. this.host = "localhost";
  22. this.database = "minefus";
  23. this.user = "root";
  24. this.pass = "";
  25. }
  26.  
  27. public void sqlConnection(){
  28. if(!isConnected())
  29. try {
  30. connection = DriverManager.getConnection(urlbase + host + "/" + database, user, pass);
  31. System.out.println("Connexion a la base de donne etabli");
  32. } catch (SQLException e) {
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. public void sqlDeconnection(){
  38. if(isConnected())
  39. try {
  40. connection.close();
  41. } catch (SQLException e) {
  42. System.err.println("Erreur dans la base de donnee");
  43. e.printStackTrace();
  44. }
  45. }
  46.  
  47. public boolean isConnected(){
  48. return connection != null;
  49. }
  50.  
  51. public Connection getConnection(){
  52. return connection;
  53. }
  54.  
  55. }
Add Comment
Please, Sign In to add comment