Advertisement
Guest User

MainPlugin

a guest
Oct 26th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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.  
  7. import org.bukkit.plugin.java.JavaPlugin;
  8.  
  9. public class MainPlugin extends JavaPlugin{
  10.  
  11. /*-- --*/
  12. // Database MySQL
  13. final String username = "root";
  14. final String password = "";
  15. final String url = "jdbc:mysql://localhost:3306/minecraft";
  16.  
  17. public static Connection connection;
  18. /*-- --*/
  19.  
  20. public void onEnable()
  21. {
  22. /*-- Load SelectCharacter Class --*/
  23. getServer().getPluginManager().registerEvents(new SelectCharacter(this), this);
  24.  
  25. // Database MySQL
  26. try
  27. {
  28. Class.forName("com.mysql.jdbc.Driver");
  29. }
  30. catch(ClassNotFoundException e)
  31. {
  32. e.printStackTrace();
  33. System.err.println("jdbc driver unavailable!");
  34. }
  35.  
  36. try
  37. {
  38. connection = DriverManager.getConnection(url,username,password);
  39. }
  40. catch(SQLException e)
  41. {
  42. e.printStackTrace();
  43. }
  44. }
  45.  
  46. public void onDisable()
  47. {
  48. try
  49. {
  50. if(connection!=null && !connection.isClosed())
  51. {
  52. connection.close();
  53. }
  54. }
  55. catch(Exception e)
  56. {
  57. e.printStackTrace();
  58. }
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement