DataBank.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package me.km.databank;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import me.km.api.Module;
  6. import net.minecraft.util.text.TextFormatting;
  7. public class DataBank extends Module
  8. {
  9. private Connection c;
  10. public DataBank(String mname, String prefix, TextFormatting color)
  11. {
  12. super(mname, prefix, color);
  13. }
  14. public boolean openDataBankConnection(String user, String password)
  15. {
  16. c = null;
  17. try
  18. {
  19. // The newInstance() call is a work around for some broken Java implementations
  20. Class.forName("com.mysql.jdbc.Driver").newInstance();
  21. c = DriverManager.getConnection("jdbc:mysql://localhost/minecraft?autoReconnect=true", user, password);
  22. this.sendToConsole("Die Verbindung wurde erfolgreich aufgebaut.");
  23. return true;
  24. }
  25. catch(SQLException | ClassNotFoundException | InstantiationException | IllegalAccessException ex)
  26. {
  27. this.sendWarningToConsole(ex.getMessage());
  28. return false;
  29. }
  30. }
  31. public void closeDataBankConnection()
  32. {
  33. try
  34. {
  35. c.close();
  36. this.sendToConsole("Die Verbindung wurde erfolgreich unterbrochen.");
  37. }
  38. catch (SQLException ex)
  39. {
  40. this.sendWarningToConsole(ex.getMessage());
  41. }
  42. catch (NullPointerException ex)
  43. {
  44. }
  45. }
  46. public Connection getConnection()
  47. {
  48. /*try
  49. {
  50. if(c.isClosed())
  51. {
  52. openDataBankConnection();
  53. }
  54. }
  55. catch(SQLException ex)
  56. {
  57. }*/
  58. return c;
  59. }
  60. }