Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. package de.austriaminer.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. import org.bukkit.OfflinePlayer;
  10.  
  11. import com.mysql.jdbc.PreparedStatement;
  12.  
  13. public class MySQL
  14. {
  15. private String HOST = "";
  16. private String DATABASE = "";
  17. private String USER = "";
  18. private String PASSWORD = "";
  19. private static Connection con;
  20.  
  21. public MySQL(String host, String database, String user, String password)
  22. {
  23. this.HOST = host;
  24. this.DATABASE = database;
  25. this.USER = user;
  26. this.PASSWORD = password;
  27.  
  28. connect();
  29. }
  30.  
  31. @SuppressWarnings("static-access")
  32. public void connect()
  33. {
  34. try
  35. {
  36. this.con = DriverManager.getConnection("jdbc:mysql://" + this.HOST + ":3306/" + this.DATABASE + "?autoReconnect=true", this.USER, this.PASSWORD);
  37. System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
  38. }
  39. catch (SQLException e)
  40. {
  41. System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
  42. }
  43. }
  44.  
  45. @SuppressWarnings("static-access")
  46. public void close()
  47. {
  48. try
  49. {
  50. if (this.con != null)
  51. {
  52. this.con.close();
  53. System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
  54. }
  55. }
  56. catch (SQLException e)
  57. {
  58. System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
  59. }
  60. }
  61.  
  62. public void update(String qry)
  63. {
  64. try
  65. {
  66. @SuppressWarnings("static-access")
  67. Statement st = this.con.createStatement();
  68. st.executeUpdate(qry);
  69. st.close();
  70. }
  71. catch (SQLException e)
  72. {
  73. connect();
  74. System.err.println(e);
  75. }
  76. }
  77.  
  78. public ResultSet query(String qry)
  79. {
  80. ResultSet rs = null;
  81. try
  82. {
  83. @SuppressWarnings("static-access")
  84. Statement st = this.con.createStatement();
  85. rs = st.executeQuery(qry);
  86. }
  87. catch (SQLException e)
  88. {
  89. connect();
  90. System.err.println(e);
  91. }
  92. return rs;
  93. }
  94.  
  95. @SuppressWarnings("static-access")
  96. public void checkConn()
  97. {
  98. try
  99. {
  100. if (this.con.isClosed()) {
  101. connect();
  102. }
  103. }
  104. catch (SQLException e)
  105. {
  106. e.printStackTrace();
  107. }
  108. }
  109. public static int getRank(OfflinePlayer target)
  110. {
  111. int rank = -1;
  112. try
  113. {
  114. PreparedStatement ps = (PreparedStatement)con.prepareStatement("SELECT * FROM FFA_basic_Stats ORDER BY KILLS DESC");
  115. ResultSet result = ps.executeQuery();
  116. while (result.next())
  117. {
  118. String uuid2 = result.getString("UUID");
  119. if (uuid2.equalsIgnoreCase(target.getUniqueId().toString()))
  120. {
  121. rank = result.getRow();
  122. break;
  123. }
  124. }
  125. result.close();
  126. ps.close();
  127. }
  128. catch (Exception ex)
  129. {
  130. ex.printStackTrace();
  131. }
  132. return rank;
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement