Advertisement
Guest User

Untitled

a guest
Jan 6th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. package fr.intensepvp.proxy.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class MySQL {
  8.  
  9. private Connection co;
  10.  
  11. public void connect(String host, String database, int port, String user, String password) {
  12. if(!isConnected()) {
  13. try {
  14. co = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
  15. } catch(SQLException e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. }
  20.  
  21. public void disconnect() {
  22. if(isConnected()) {
  23. try {
  24. co.close();
  25. } catch(SQLException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. }
  30.  
  31. public boolean isConnected() {
  32. try {
  33. if((co == null) || (co.isClosed()) || (co.isValid(5))) {
  34. return false;
  35. }
  36. return true;
  37. } catch(SQLException e) {
  38. e.printStackTrace();
  39. }
  40. return false;
  41. }
  42.  
  43. public Connection getConnection() {
  44. return co;
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement