Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. package MySQL;
  2.  
  3. import Main.DekaMain;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.io.PrintStream;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.ResultSet;
  10. import java.sql.SQLException;
  11. import java.sql.Statement;
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.command.ConsoleCommandSender;
  14. import org.bukkit.configuration.file.FileConfiguration;
  15. import org.bukkit.configuration.file.FileConfigurationOptions;
  16. import org.bukkit.configuration.file.YamlConfiguration;
  17.  
  18. public class MySQL
  19. {
  20. public static String Host;
  21. public static String Datenbank;
  22. public static String Port;
  23. public static String Username;
  24. public static String Password;
  25. public static Connection con;
  26.  
  27. public MySQL(String user, String pass, String host2, String dB) {}
  28.  
  29. public static void Connect()
  30. {
  31. if (!isConnected()) {
  32. try
  33. {
  34. con = DriverManager.getConnection("jdbc:mysql://" + Host + ":" + Port + "/" + Datenbank + "?user=" + Username + "&password=" + Password + "&autoReconnect=true");
  35. Bukkit.getConsoleSender().sendMessage(DekaMain.Prefix + "�aDie Verbindung zur MySQL wurde hergestellt!");
  36. }
  37. catch (SQLException ex)
  38. {
  39. Bukkit.getConsoleSender().sendMessage(DekaMain.Error + "�cDie Verbindung zur MySQL ist fehlgeschlagen!");
  40. }
  41. }
  42. }
  43.  
  44. public static void close()
  45. {
  46. if (isConnected()) {
  47. try
  48. {
  49. con.close();
  50. Bukkit.getConsoleSender().sendMessage(DekaMain.Prefix + "�aDie Verbindung zur MySQL wurde erfolgreich beendet!");
  51. }
  52. catch (SQLException ex)
  53. {
  54. Bukkit.getConsoleSender().sendMessage(DekaMain.Error + "�cFehler beim beenden der Verbindung zur MySQL!");
  55. }
  56. }
  57. }
  58.  
  59. public static boolean isConnected()
  60. {
  61. return con != null;
  62. }
  63.  
  64. public static void update(String qry)
  65. {
  66. if (isConnected()) {
  67. try
  68. {
  69. con.createStatement().executeUpdate(qry);
  70. }
  71. catch (SQLException ex)
  72. {
  73. Bukkit.getConsoleSender().sendMessage(DekaMain.Error + "�cKonnte das Update �7(�e" + qry + "�7) �cnicht ausf��hren!");
  74. }
  75. }
  76. }
  77.  
  78. public static void createTable()
  79. {
  80. if (isConnected()) {
  81. try
  82. {
  83. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Knockbackffa (UUID VARCHAR(100), KILLS int, TODE int, COINS int)");
  84. Bukkit.getConsoleSender().sendMessage("�aDie Table wurde erstellt!");
  85. }
  86. catch (SQLException localSQLException) {}
  87. }
  88. }
  89.  
  90. public static ResultSet query(String qry)
  91. {
  92. ResultSet rs = null;
  93. try
  94. {
  95. Statement st = con.createStatement();
  96. rs = st.executeQuery(qry);
  97. }
  98. catch (SQLException ex)
  99. {
  100. Connect();
  101. System.err.println(ex);
  102. }
  103. return rs;
  104. }
  105.  
  106. public static File getMySQLFile()
  107. {
  108. return new File("plugins/Knockbackffa", "MySQL.yml");
  109. }
  110.  
  111. public static FileConfiguration getMySQLFileConfiguration()
  112. {
  113. return YamlConfiguration.loadConfiguration(getMySQLFile());
  114. }
  115.  
  116. public static void setStandardMySQL()
  117. {
  118. FileConfiguration cfg = getMySQLFileConfiguration();
  119.  
  120. cfg.options().copyDefaults(true);
  121. cfg.addDefault("Host", "localhost");
  122. cfg.addDefault("Datenbank", "Datenbank");
  123. cfg.addDefault("Port", "3306");
  124. cfg.addDefault("Username", "root");
  125. cfg.addDefault("Password", "Password");
  126. try
  127. {
  128. cfg.save(getMySQLFile());
  129. }
  130. catch (IOException localIOException) {}
  131. }
  132.  
  133. public static void readMySQL()
  134. {
  135. FileConfiguration cfg = getMySQLFileConfiguration();
  136. Host = cfg.getString("Host");
  137. Datenbank = cfg.getString("Datenbank");
  138. Port = cfg.getString("Port");
  139. Username = cfg.getString("Username");
  140. Password = cfg.getString("Password");
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement