Advertisement
raphtnt

Untitled

Sep 9th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. import net.md_5.bungee.api.ChatColor;
  8.  
  9. public class MySQL {
  10.  
  11. private Connection conn;
  12.  
  13.  
  14. public void connect(String host, int port, String database, String user, String password){
  15. if(!isConnected()){
  16. try {
  17. conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
  18. System.out.println("[HardSword] - [MySQL] Connection etablie avec le serveur !");
  19. System.out.println("-----------------------------");
  20. } catch (SQLException e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. }
  25.  
  26. public void disconnect(){
  27. if(isConnected()){
  28. try {
  29. conn.close();
  30. } catch (SQLException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. }
  35.  
  36. public boolean isConnected(){
  37. try {
  38. if((conn == null) || (conn.isClosed()) || conn.isValid(5)){
  39. return false;
  40. }
  41. return true;
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. }
  45. return false;
  46. }
  47.  
  48. public Connection getConnection(){
  49. return conn;
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement