Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. public class MySQL {
  2.  
  3. Main main;
  4.  
  5. public MySQL(Main main) {
  6.  
  7. this.main = main;
  8.  
  9. }
  10.  
  11. public static String username = "Pex";
  12. public static String password = "12345";
  13. public static String database = "System";
  14. public static String host = "localhost";
  15. public static Connection con;
  16.  
  17. public static boolean isConnected() {
  18. return con != null;
  19. }
  20.  
  21. public void createTable() {
  22.  
  23. update("CREATE TABLE IF NOT EXISTS eSystem_Users(Name VARCHAR(16), UUID VARCHAR(64), isNicking VARCHAR(10));");
  24.  
  25. }
  26.  
  27.  
  28.  
  29. public static void connect() {
  30.  
  31. if(!isConnected()) {
  32.  
  33. try {
  34.  
  35. con = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + database + "?autoReconnect=true", username, password);
  36. Bukkit.getConsoleSender().sendMessage("[MySQL] Erfolgreich zur MySQL-Datenbank verbunden");
  37.  
  38. } catch(SQLException e) {
  39.  
  40. Bukkit.getConsoleSender().sendMessage("[MySQL] Es konnte nicht zur MySQL-Datenbank verbunden werden");
  41. e.printStackTrace();
  42.  
  43. }
  44.  
  45. }
  46.  
  47. }
  48.  
  49. public static void close() {
  50.  
  51. try {
  52.  
  53. con.close();
  54. con = null;
  55. Bukkit.getConsoleSender().sendMessage("[MySQL] Die MySQL Verbindung wurde getrennt");
  56.  
  57. } catch(SQLException e) {
  58.  
  59. Bukkit.getConsoleSender().sendMessage("[MySQL] Die MySQL Verbindung konnte nicht geschlossen werden");
  60. e.printStackTrace();
  61.  
  62. }
  63.  
  64. }
  65.  
  66. public void update(String qry) {
  67.  
  68. if(isConnected()) {
  69.  
  70. try {
  71.  
  72. con.createStatement().executeUpdate(qry);
  73.  
  74. } catch(SQLException e) {
  75.  
  76. e.printStackTrace();
  77.  
  78. }
  79.  
  80. }
  81.  
  82. }
  83.  
  84. public ResultSet getResult(String qry) {
  85.  
  86. try {
  87.  
  88. return con.createStatement().executeQuery(qry);
  89.  
  90. } catch(SQLException e) {
  91.  
  92. e.printStackTrace();
  93.  
  94. }
  95.  
  96. return null;
  97.  
  98. }
  99.  
  100. public static String getMySQLStatus() {
  101.  
  102. if(isConnected()) {
  103.  
  104. return "§aOn";
  105.  
  106. } else {
  107.  
  108. return "§cOff";
  109.  
  110. }
  111.  
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement