Advertisement
Guest User

Untitled

a guest
Apr 25th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. public class DatabaseManager {
  2.  
  3. private final Clans plugin;
  4. @Getter
  5. private static Connection connection;
  6.  
  7. public DatabaseManager(final Clans plugin) {
  8. this.plugin = plugin;
  9. }
  10.  
  11. public void connect() {
  12. if (!isConnected())
  13. try {
  14. connection = DriverManager.getConnection("jdbc:mysql://" + this.plugin.getData().getMysqlHostName() + ":" + this.plugin.getData().getMysqlPort() + "/" + this.plugin.getData().getMysqlDatabase() + "?sslmode=require", this.plugin.getData().getMysqlUsername(), this.plugin.getData().getMysqlPassword());
  15. System.out.println("clans connected to database");
  16. } catch (SQLException e) {
  17. e.printStackTrace();
  18. }
  19. }
  20.  
  21. public static void disconnect() {
  22. if (isConnected())
  23. try {
  24. connection.close();
  25. System.out.println("clans disconnected from database");
  26. } catch (SQLException e) {
  27. e.printStackTrace();
  28. }
  29. }
  30.  
  31. public static boolean isConnected() {
  32. return !(connection == null);
  33. }
  34.  
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement