danik159

Untitled

Aug 5th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 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. getCommand("reports").setExecutor(new Reports());
  21. Bukkit.getPluginManager().registerEvents(this, this);
  22. host = "localhost";
  23. port = 3306;
  24. database = "playerreport";
  25. username = "root";
  26. password = "";
  27. try {
  28. openConnection();
  29.  
  30. System.out.println(ChatColor.GREEN + "MySQL Connected!");
  31. }catch (SQLException x) {
  32. x.printStackTrace();
  33. }
  34.  
  35. }
  36.  
  37. public static PreparedStatement prepareState(String query) {
  38. PreparedStatement ps = null;
  39. try {
  40. ps = connection.prepareStatement(query);
  41. } catch (SQLException x) {
  42. x.printStackTrace();
  43. }
  44. return ps;
  45. }
  46. private void openConnection() throws SQLException {
  47. if (connection != null && !connection.isClosed()) {
  48. return;
  49. }
  50.  
  51. connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
  52. }
  53.  
  54. }
Add Comment
Please, Sign In to add comment