Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public class MYSQL extends JavaPlugin {
  2.  
  3. private Connection connection;
  4. public String host, database, username, password;
  5. public int database_port;
  6.  
  7. @Override
  8. public void onEnable() {
  9. setupMYSQL();
  10. }
  11.  
  12. private void setupMYSQL() {
  13. host = "localhost";
  14. database = "test";
  15. username = "root";
  16. password = "password";
  17. database_port = 3306;
  18.  
  19. setupConnection();
  20. }
  21.  
  22. private void setupConnection() {
  23. try {
  24.  
  25. synchronized (this) {
  26. if (getConnection() != null && !getConnection().isClosed()) {
  27. return;
  28. }
  29.  
  30. Class.forName("com.mysql.jdbc.Driver");
  31. setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.database_port + "/" + this.database, this.username, this.password));
  32.  
  33. Bukkit.getConsoleSender().sendMessage("§aMYSQL Connection Establish");
  34. }
  35.  
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. } catch (ClassNotFoundException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42.  
  43. public Connection getConnection() {
  44. return connection;
  45. }
  46.  
  47. public void setConnection(Connection connection) {
  48. this.connection = connection;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement