Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. package Mars.PVP.SQL;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.command.ConsoleCommandSender;
  10.  
  11. public class MySQL {
  12. public static String username;
  13. public static String password;
  14. public static String database;
  15. public static String host;
  16. public static int port;
  17. public static Connection con;
  18. public static MySQL mysql;
  19.  
  20. public static boolean isConnected() {
  21. return con != null;
  22. }
  23.  
  24. public static void connect() {
  25. if (!isConnected()) {
  26. try {
  27. con = java.sql.DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database,
  28. username, password);
  29. Bukkit.getConsoleSender().sendMessage("§aMySQL connection established succesfully");
  30. } catch (SQLException e) {
  31. e.printStackTrace();
  32. Bukkit.getConsoleSender().sendMessage("§cMySQL connection failed!");
  33. }
  34. }
  35. }
  36.  
  37. public static void close() {
  38. if (isConnected()) {
  39. try {
  40. con.close();
  41. Bukkit.getConsoleSender().sendMessage("§2MySQL connection closed succesfully!");
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. }
  45. }
  46. }
  47.  
  48. public static void update(String qry) {
  49. if (isConnected()) {
  50. try {
  51. PreparedStatement pt = con.prepareStatement(qry);
  52. pt.executeUpdate();
  53. } catch (SQLException e) {
  54. e.printStackTrace();
  55. }
  56. }
  57. }
  58.  
  59. public static java.sql.ResultSet getResult(String qry) {
  60. if (isConnected()) {
  61. try {
  62. PreparedStatement pt = con.prepareStatement(qry);
  63.  
  64. return pt.executeQuery();
  65. } catch (SQLException e) {
  66. e.printStackTrace();
  67. return null;
  68. }
  69. }
  70. return null;
  71. }
  72.  
  73. public static void createTables() {
  74. if (isConnected()) {
  75. try {
  76. con.createStatement().executeUpdate(
  77. "CREATE TABLE IF NOT EXISTS FFA (Playername VARCHAR(100), Kills int, Deaths int,Souls int,Selector VARCHAR(100), Points int)");
  78. } catch (SQLException e) {
  79. e.printStackTrace();
  80. }
  81. }
  82. }
  83.  
  84. public static void createTableKillStreaks() {
  85. if (isConnected()) {
  86. try {
  87. con.createStatement().executeUpdate(
  88. "CREATE TABLE IF NOT EXISTS KillStreakSQL (Playername VARCHAR(100), KillStreak int)");
  89. } catch (SQLException e) {
  90. e.printStackTrace();
  91. }
  92. }
  93. }
  94.  
  95. public static void createTableShop() {
  96. if (isConnected()) {
  97. try {
  98. con.createStatement().executeUpdate(
  99. "CREATE TABLE IF NOT EXISTS FFASHOP (Playername VARCHAR(100), Item VARCHAR(100), Buy VARCHAR(100))");
  100. } catch (SQLException e) {
  101. e.printStackTrace();
  102. }
  103. }
  104. }
  105.  
  106. public ResultSet query(String s) {
  107. ResultSet executeQuery = null;
  108. try {
  109. executeQuery = this.con.createStatement().executeQuery(s);
  110. } catch (SQLException ex) {
  111. connect();
  112. System.err.println(ex);
  113. }
  114. return executeQuery;
  115. }
  116.  
  117. public static Integer getKills1(String s) {
  118. Integer n = Integer.valueOf(0);
  119. if (Stats.exists(s)) {
  120. try {
  121. ResultSet query = Mars.PVP.SQL.MySQL.mysql.query("SELECT * FROM FFA WHERE Playername '" + s + "'");
  122. if (query.next())
  123. Integer.valueOf(query.getInt("KILLS"));
  124. n = Integer.valueOf(query.getInt("KILLS"));
  125. } catch (SQLException ex) {
  126. ex.printStackTrace();
  127. }
  128. } else {
  129. Stats.createPlayer(s);
  130. Stats.getKills(s);
  131. }
  132. return n;
  133. }
  134.  
  135. public static boolean isConnected1() {
  136. return con != null;
  137. }
  138.  
  139. public static Connection getConnection() {
  140. return con;
  141. }
  142.  
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement