Advertisement
Guest User

Untitled

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