danik159

Untitled

Aug 4th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package com.chickenstyle.report;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10.  
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13.  
  14. public class Main extends JavaPlugin implements Listener {
  15. private static Connection connection;
  16. private String host, database, username, password;
  17. private int port;
  18. public void onEnable() {
  19. getCommand("report").setExecutor(new Report());
  20. Bukkit.getPluginManager().registerEvents(this, this);
  21. host = "localhost";
  22. port = 3306;
  23. database = "player_report";
  24. username = "root";
  25. password = "";
  26. try {
  27. openConnection();
  28.  
  29. System.out.println(ChatColor.GREEN + "MySQL Connected!");
  30. }catch (SQLException x) {
  31. x.printStackTrace();
  32. }
  33.  
  34. }
  35.  
  36. public static PreparedStatement prepareState(String query) {
  37. PreparedStatement ps = null;
  38. try {
  39. ps = connection.prepareStatement(query);
  40. } catch (SQLException x) {
  41. x.printStackTrace();
  42. }
  43. return ps;
  44. }
  45. private void openConnection() throws SQLException {
  46. if (connection != null && !connection.isClosed()) {
  47. return;
  48. }
  49.  
  50. connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
  51. }
  52.  
  53. }
Add Comment
Please, Sign In to add comment