Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public class Main extends JavaPlugin {
  2. private Connection connection;
  3. public String host, database, username, password;
  4. public int port;
  5.  
  6. public void onEnable() {
  7. loadConfig();
  8. mysqlSetup();
  9. }
  10. public void onDisable() {
  11. }
  12.  
  13. private void loadConfig() {
  14. getConfig().options().copyDefaults(true);
  15. saveConfig();
  16. }
  17.  
  18. public void mysqlSetup(){
  19. host = "localhost";
  20. port = 3306;
  21. database = "test";
  22. username = "root";
  23. password = "password";
  24.  
  25. try {
  26. synchronized (this) {
  27. if(getConnection() != null && !getConnection().isClosed()) {
  28. return;
  29. }
  30.  
  31. Class.forName("com.mysql.jdbc.Driver");
  32. setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":"
  33. + this.port + "/" + this.database, this.username, this.password));
  34.  
  35. Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[MySQL] Server Connected!");
  36. }
  37. }catch(SQLException e) {
  38. e.printStackTrace();
  39. }catch(ClassNotFoundException e) {
  40. e.printStackTrace();
  41. }
  42.  
  43.  
  44. }
  45. public Connection getConnection() {
  46. return connection;
  47. }
  48. public void setConnection(Connection connection) {
  49. this.connection = connection;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement