Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. package de.ToxicGaming.Bungee.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class MySQL {
  8.  
  9. public String host;
  10. public String port;
  11. public String database;
  12. public String username;
  13. public Connection con;
  14.  
  15. public void connect(String host, String port, String database, String username) {
  16. if (!isConnected()) {
  17. this.database = database;
  18. this.port = port;
  19. this.host = host;
  20. this.username = username;
  21. try {
  22. con = DriverManager.getConnection(
  23. "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username,
  24. password);
  25. System.out.println("Verbindung zur Datenbank " + database + " wurde erfolgreich aufgebaut!");
  26. } catch (Exception e) {
  27. e.printStackTrace();
  28. System.out.println("Verbindung zur Datenbank " + database + " wurde nicht erfolgreich aufgebaut!");
  29. }
  30. }
  31. }
  32.  
  33. public void disconnect() {
  34. if (isConnected()) {
  35. try {
  36. con.close();
  37. con = null;
  38. System.out.println("Verbindung zur Datenbank " + database + " wurde erfolgreich geschlossen!");
  39. } catch (SQLException e) {
  40. System.out.println("Verbindung zur Datenbank " + database + " wurde nicht erfolgreich geschlossen!");
  41. }
  42. }
  43. }
  44.  
  45. public boolean isConnected() {
  46. return (con == null ? false : true);
  47. }
  48.  
  49. public Connection getConnection() {
  50. return con;
  51. }
  52. public String password = "";
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement