Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. package me.freaktube.nico.mysql;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.PrintStream;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.sql.Statement;
  11. import org.bukkit.Bukkit;
  12. import org.bukkit.command.ConsoleCommandSender;
  13. import org.bukkit.configuration.file.FileConfiguration;
  14. import org.bukkit.configuration.file.FileConfigurationOptions;
  15. import org.bukkit.configuration.file.YamlConfiguration;
  16.  
  17. public class MYSQL_MYSQL
  18. {
  19. public static String username;
  20. public static String password;
  21. public static String database;
  22. public static String host;
  23. public static String port;
  24. public static Connection con;
  25.  
  26. public MYSQL_MYSQL(String user, String pass, String host2, String dB)
  27. {
  28. }
  29.  
  30. public static void connect()
  31. {
  32. if (!isConnected())
  33. try {
  34. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  35. Bukkit.getConsoleSender().sendMessage("§8[§6SurvivalSystem§8] §aMySQL Verbindubg wurde erfolgreich hergestellt!");
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40.  
  41. public static void close() {
  42. if (isConnected())
  43. try {
  44. con.close();
  45. Bukkit.getConsoleSender().sendMessage("§8[§6SurvivalSystem§8] §aMySQL Verbindung wurde erfolgreich getrennt!");
  46. } catch (SQLException e) {
  47. e.printStackTrace();
  48. }
  49. }
  50.  
  51. public static boolean isConnected() {
  52. return con != null;
  53. }
  54.  
  55. public static Connection getConnection() {
  56. return con;
  57. }
  58.  
  59. public static void createTable() {
  60. if (isConnected())
  61. try {
  62. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS STATS (UUID VARCHAR(100), KILLS int, DEATHS int, MÜNZEN int, SPIN int)");
  63. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BANSYSTEM (UUID VARCHAR(100), VON VARCHAR(100), GRUND VARCHAR(100), ENDE VARCHAR(100))");
  64. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS MUTESYSTEM (UUID VARCHAR(100), VON VARCHAR(100), GRUND VARCHAR(100), ENDE VARCHAR(100))");
  65. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Bounty (id INT AUTO_INCREMENT PRIMARY KEY, UUID VARCHAR(100), NAME VARCHAR(100), HASBOUNTY int, STARTBOUNTY int , BOUNTY int , SETTER VARCHAR(100) , KILLER VARCHAR(100))");
  66. Bukkit.getConsoleSender().sendMessage("§8[§6SurvivalSystem§8] §aMySQL Tabele wurde erstellt!");
  67. } catch (SQLException e) {
  68. e.printStackTrace();
  69. }
  70. }
  71.  
  72. public static void update(String qry)
  73. {
  74. if (isConnected())
  75. try {
  76. con.createStatement().executeUpdate(qry);
  77. } catch (SQLException e) {
  78. e.printStackTrace();
  79. }
  80. }
  81.  
  82. public static ResultSet getResult(String qry) {
  83. ResultSet rs = null;
  84. try {
  85. Statement st = con.createStatement();
  86. rs = st.executeQuery(qry);
  87. } catch (SQLException e) {
  88. connect();
  89. System.err.println(e);
  90. }
  91. return rs;
  92. }
  93.  
  94. public static File getMySQLFile() {
  95. return new File("plugins/SurvivalSystem", "MySQL.yml");
  96. }
  97.  
  98. public static FileConfiguration getMySQLFileConfiguration() {
  99. return YamlConfiguration.loadConfiguration(getMySQLFile());
  100. }
  101.  
  102. public static void setStandardMySQL() {
  103. FileConfiguration cfg = getMySQLFileConfiguration();
  104.  
  105. cfg.options().copyDefaults(true);
  106. cfg.addDefault("username", "root");
  107. cfg.addDefault("password", "password");
  108. cfg.addDefault("database", "localhost");
  109. cfg.addDefault("host", "localhost");
  110. cfg.addDefault("port", "3306");
  111. try {
  112. cfg.save(getMySQLFile());
  113. } catch (IOException e) {
  114. e.printStackTrace();
  115. }
  116. }
  117.  
  118. public static void readMySQL() {
  119. FileConfiguration cfg = getMySQLFileConfiguration();
  120. username = cfg.getString("username");
  121. password = cfg.getString("password");
  122. database = cfg.getString("database");
  123. host = cfg.getString("host");
  124. port = cfg.getString("port");
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement