Advertisement
Guest User

Untitled

a guest
Oct 4th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package de.setoras.potionpvp.main;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. public class DB extends JavaPlugin {
  11. DB mysql = new DB();
  12.  
  13. private Connection connection;
  14. private String host, database, username, password;
  15. private int port;
  16.  
  17. @Override
  18. public void onEnable() {
  19. host = "localhost";
  20. port = 3306;
  21. database = "Minecraft";
  22. username = "user";
  23. password = "pass";
  24. try {
  25. openConnection();
  26. Statement statement = connection.createStatement();
  27. } catch (ClassNotFoundException e) {
  28. e.printStackTrace();
  29. } catch (SQLException e) {
  30. e.printStackTrace();
  31. }
  32. }
  33.  
  34. @Override
  35. public void onDisable() {
  36. }
  37.  
  38. public void openConnection() throws SQLException, ClassNotFoundException {
  39. if (connection != null && !connection.isClosed()) {
  40. return;
  41. }
  42.  
  43. synchronized (this) {
  44. if (connection != null && !connection.isClosed()) {
  45. return;
  46. }
  47. Class.forName("com.mysql.jdbc.Driver");
  48. connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement