Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package eu.iteije.sql;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.event.Listener;
  6. import org.bukkit.plugin.java.JavaPlugin;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.Driver;
  10. import java.sql.DriverManager;
  11. import java.sql.SQLException;
  12.  
  13. public class MysqlMain extends JavaPlugin {
  14.  
  15. private Connection connection;
  16. public String host, database, username, password;
  17. public int port;
  18.  
  19. public void onEnable() {
  20. mysqlSetup();
  21. }
  22. public void onDisable() {
  23.  
  24. }
  25.  
  26. public void mysqlSetup() {
  27. host = "api.hatrex.net";
  28. port = 3306;
  29. database = "admin_test";
  30. username = "admin_root";
  31. password = "jquery";
  32.  
  33. try {
  34. synchronized (this) {
  35. if (getConnection() != null && !getConnection().isClosed()) {
  36. return;
  37. }
  38.  
  39. Class.forName("com.mysql.jdbc.Driver");
  40. setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":"
  41. + this.port + "/" + this.database, this.username, this.password));
  42.  
  43. Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "MySQL connected!");
  44. }
  45. } catch (SQLException e) {
  46. e.printStackTrace();
  47. } catch (ClassNotFoundException e) {
  48. e.printStackTrace();
  49. }
  50. }
  51.  
  52. public Connection getConnection() {
  53. return connection;
  54. }
  55.  
  56. public void setConnection(Connection connection) {
  57. this.connection = connection;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement