Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. private String url_base, host, name, username, password, table;
  2. private Connection connection;
  3.  
  4. public MysqlDatabase(String url_base, String host, String name, String username, String password, String table) {
  5. this.url_base = url_base;
  6. this.host = host;
  7. this.name = name;
  8. this.username = username;
  9. this.password = password;
  10. this.table = table;
  11. }
  12.  
  13. public void connection(){
  14. if (!isConnected()) {
  15. try{
  16. connection = DriverManager.getConnection(url_base + host + "/" + name, username, password);
  17. }catch (SQLException e) {
  18. e.printStackTrace();
  19. }
  20. }
  21. }
  22.  
  23. public void deconnection() {
  24. if (isConnected()) {
  25. try {
  26. connection.close();
  27. }catch (SQLException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. }
  32.  
  33. public boolean isConnected() {
  34. try{
  35. if((connection == null) || (connection.isClosed() || (!connection.isValid(5)))) {
  36. return false;
  37. }else{
  38. return true;
  39. }
  40. }catch (SQLException e) {
  41. e.printStackTrace();
  42. }
  43. return false;
  44. }
  45.  
  46. private Connection getConnection(){
  47. return connection;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement