Advertisement
Guest User

Untitled

a guest
May 3rd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. private Main plugin;
  2. private Connection connection;
  3.  
  4. public MySQLHKNH(Main plugin) {
  5. this.plugin = plugin;
  6. }
  7.  
  8. public void mysqlSetup() {
  9. String host = plugin.config.getIp();
  10. int port = 3306;
  11. String database = plugin.config.getDatabaseHKNH();
  12. String username = plugin.config.getUsername();
  13. String password = plugin.config.getPassword();
  14. try {
  15. synchronized (this) {
  16. if (getConnection() != null && !getConnection().isClosed()) {
  17. return;
  18. }
  19. Class.forName("com.mysql.cj.jdbc.Driver");
  20. setConnection(
  21. DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true&serverTimezone=UTC", username, password));
  22. }
  23. } catch (SQLException | ClassNotFoundException e) {
  24. e.printStackTrace();
  25. }
  26. }
  27.  
  28. private Connection getConnection() {
  29. return connection;
  30. }
  31.  
  32. private void setConnection(Connection connection) {
  33. this.connection = connection;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement