Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package me.terabitth.SelectChar;
  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 MainPlugin extends JavaPlugin{
  11.  
  12. /*-- --*/
  13. // Database MySQL
  14. String host = "localhost";
  15. int port = 3306;
  16. String database = "minecraft";
  17. String username = "root";
  18. String password = "";
  19.  
  20. public static Connection connection;
  21. /*-- --*/
  22.  
  23. public void onEnable()
  24. {
  25. /*-- Load SelectCharacter Class --*/
  26. getServer().getPluginManager().registerEvents(new SelectCharacter(this), this);
  27.  
  28. // Database MySQL
  29. try
  30. {
  31. openConnection();
  32. Statement statement = connection.createStatement();
  33. }
  34. catch (ClassNotFoundException e)
  35. {
  36. e.printStackTrace();
  37. }
  38. catch (SQLException e)
  39. {
  40. e.printStackTrace();
  41. }
  42.  
  43. }
  44.  
  45. public void openConnection() throws SQLException, ClassNotFoundException
  46. {
  47. if (connection != null && !connection.isClosed()) {
  48. return;
  49. }
  50.  
  51. synchronized (this) {
  52. if (connection != null && !connection.isClosed()) {
  53. return;
  54. }
  55. Class.forName("com.mysql.jdbc.Driver");
  56. connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
  57. }
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement