Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.austriaminer.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.OfflinePlayer;
- import com.mysql.jdbc.PreparedStatement;
- //MYSQL Klasse connecten
- public class MySQL
- {
- private String HOST = "";
- private String DATABASE = "";
- private String USER = "";
- private String PASSWORD = "";
- private static Connection con;
- public MySQL(String host, String database, String user, String password)
- {
- this.HOST = host;
- this.DATABASE = database;
- this.USER = user;
- this.PASSWORD = password;
- connect();
- }
- @SuppressWarnings("static-access")
- public void connect()
- {
- try
- {
- this.con = DriverManager.getConnection("jdbc:mysql://" + this.HOST + ":3306/" + this.DATABASE + "?autoReconnect=true", this.USER, this.PASSWORD);
- System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
- }
- catch (SQLException e)
- {
- System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
- }
- }
- @SuppressWarnings("static-access")
- public void close()
- {
- try
- {
- if (this.con != null)
- {
- this.con.close();
- System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
- }
- }
- catch (SQLException e)
- {
- System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
- }
- }
- public void update(String qry)
- {
- try
- {
- @SuppressWarnings("static-access")
- Statement st = this.con.createStatement();
- st.executeUpdate(qry);
- st.close();
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- }
- public ResultSet query(String qry)
- {
- ResultSet rs = null;
- try
- {
- @SuppressWarnings("static-access")
- Statement st = this.con.createStatement();
- rs = st.executeQuery(qry);
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- return rs;
- }
- @SuppressWarnings("static-access")
- public void checkConn()
- {
- try
- {
- if (this.con.isClosed()) {
- connect();
- }
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- public static int getRank(OfflinePlayer target)
- {
- int rank = -1;
- try
- {
- PreparedStatement ps = (PreparedStatement)con.prepareStatement("SELECT * FROM FFA_basic_Stats ORDER BY KILLS DESC");
- ResultSet result = ps.executeQuery();
- while (result.next())
- {
- String uuid2 = result.getString("UUID");
- if (uuid2.equalsIgnoreCase(target.getUniqueId().toString()))
- {
- rank = result.getRow();
- break;
- }
- }
- result.close();
- ps.close();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- return rank;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement