Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package net.maiky.tokens.engine;
  2.  
  3. import net.maiky.tokens.tokens;
  4. import org.bukkit.Bukkit;
  5.  
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.SQLException;
  9.  
  10. public class Mysql {
  11. private String host = "";
  12. private String port = "";
  13. private String database = "";
  14. private String username = "";
  15. private String password = "";
  16. private Connection connection;
  17.  
  18. public tokens main;
  19.  
  20. public Mysql(tokens main) {
  21. this.main = main;
  22. host = main.getConfig().getString("MySQL.host");
  23. port = main.getConfig().getString("MySQL.port");
  24. database= main.getConfig().getString("MySQL.database");
  25. username = main.getConfig().getString("MySQL.user");
  26. password = main.getConfig().getString("MySQL.password");
  27. }
  28.  
  29.  
  30. public boolean isConnected() {
  31. return (connection == null ? false : true);
  32.  
  33. }
  34.  
  35. public void connect() throws ClassNotFoundException, SQLException {
  36. if(!isConnected()) {
  37. connection = DriverManager.getConnection("jdbc:mysql://" +
  38. host + ":" + port + "/" + database + "?useSSL=false",
  39. username, password);
  40. }
  41.  
  42. }
  43. public void disconnect() {
  44. if(isConnected()) {
  45. try {
  46. connection.close();
  47. } catch (SQLException e) {
  48. //e.printStackTrace();
  49.  
  50. }
  51. }
  52. }
  53.  
  54. public Connection getConnection() {
  55. return connection;
  56. }
  57.  
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement