Advertisement
FabixModz

Untitled

May 5th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. package de.zexception.mysql;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10.  
  11. import org.bukkit.Bukkit;
  12. import org.bukkit.configuration.file.FileConfiguration;
  13. import org.bukkit.configuration.file.YamlConfiguration;
  14.  
  15. import de.zexception.main.Main;
  16.  
  17. public class 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(String user, String pass, String host2, String dB) {}
  27.  
  28. public static void connect()
  29. {
  30. if (!isConnected()) {
  31. try
  32. {
  33. con = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + database + "?autoReconnect=true", username, password);
  34. Bukkit.getConsoleSender().sendMessage(Main.prefix + "§4MySQL MySQL connected");
  35. }
  36. catch (SQLException e)
  37. {
  38. e.printStackTrace();
  39. }
  40. }
  41. }
  42.  
  43. public static void close()
  44. {
  45. if (isConnected()) {
  46. try
  47. {
  48. con.close();
  49. Bukkit.getConsoleSender().sendMessage(Main.prefix + "§4MySQL MySQL disconnected");
  50. }
  51. catch (SQLException e)
  52. {
  53. e.printStackTrace();
  54. }
  55. }
  56. }
  57.  
  58. public static boolean isConnected()
  59. {
  60. return con != null;
  61. }
  62.  
  63. public static void createTable()
  64. {
  65. if (isConnected()) {
  66. try
  67. {
  68. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Mute(UUID VARCHAR(100), STATUS int, VON VARCHAR(100), GRUND VARCHAR(100))");
  69. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS CoinsAPI (UUID VARCHAR(100), COINS int)");
  70. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Kopfgeld(UUID VARCHAR(100), STATUS int, AMOUNT int)");
  71. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Stats (UUID VARCHAR(100), ID VARCHAR(100), KILLS int, DEATHS int , WIN int , LOSE int , COINS FLOAT)");
  72. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Players (UUID VARCHAR(100), NAME VARCHAR(100))");
  73. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS AMS (UUID VARCHAR(100), AMOUNT int, UPGRADE int)");
  74. //con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Clan (NAME VARCHAR(100), INHABER VARCHAR(100), PREMIUM int, ANZAHL int, Spieler1 VARCHAR(100), Spieler2 VARCHAR(100),Spieler3 VARCHAR(100),Spieler4 VARCHAR(100),Spieler5 VARCHAR(100),Spieler6 VARCHAR(100),Spieler7 VARCHAR(100),Spieler8 VARCHAR(100),Spieler9 VARCHAR(100),Spieler10 VARCHAR(100))");
  75.  
  76.  
  77. Bukkit.getConsoleSender().sendMessage(Main.prefix + "§4MySQL MySQL Table created");
  78. }
  79. catch (SQLException e)
  80. {
  81. e.printStackTrace();
  82. }
  83. }
  84. }
  85.  
  86. public static void update(String qry)
  87. {
  88. if (isConnected()) {
  89. try
  90. {
  91. con.createStatement().executeUpdate(qry);
  92. }
  93. catch (SQLException e)
  94. {
  95. e.printStackTrace();
  96. }
  97. }
  98. }
  99.  
  100. public static ResultSet getResult(String qry)
  101. {
  102. ResultSet rs = null;
  103. try
  104. {
  105. Statement st = con.createStatement();
  106. rs = st.executeQuery(qry);
  107. }
  108. catch (SQLException e)
  109. {
  110. connect();
  111. System.err.println(e);
  112. }
  113. return rs;
  114. }
  115.  
  116. public static File getMySQLFile()
  117. {
  118. return new File("plugins/System", "MySQL.yml");
  119. }
  120.  
  121. public static FileConfiguration getMySQLFileConfiguration()
  122. {
  123. return YamlConfiguration.loadConfiguration(getMySQLFile());
  124. }
  125.  
  126. public static void setStandardMySQL()
  127. {
  128. FileConfiguration cfg = getMySQLFileConfiguration();
  129.  
  130. cfg.options().copyDefaults(true);
  131. cfg.addDefault("username", "root");
  132. cfg.addDefault("password", "password");
  133. cfg.addDefault("database", "localhost");
  134. cfg.addDefault("host", "localhost");
  135. cfg.addDefault("port", "3306");
  136. try
  137. {
  138. cfg.save(getMySQLFile());
  139. }
  140. catch (IOException e)
  141. {
  142. e.printStackTrace();
  143. }
  144. }
  145.  
  146. public static void readMySQL()
  147. {
  148. FileConfiguration cfg = getMySQLFileConfiguration();
  149. username = cfg.getString("username");
  150. password = cfg.getString("password");
  151. database = cfg.getString("database");
  152. host = cfg.getString("host");
  153. port = cfg.getString("port");
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement