Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.xCracked.MelonePvP.MySQL;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.Bukkit;
- import com.mysql.jdbc.PreparedStatement;
- import de.xCracked.MelonePvP.Main;
- public class MySQL
- {
- public static Connection con;
- public static void connect()
- {
- try
- {
- con = DriverManager.getConnection("jdbc:mysql://" + Main.host + ":3306/" + Main.database + "?autoreconnect=true", Main.user, Main.password);
- Bukkit.getConsoleSender().sendMessage("§8(§b§lMySQL§8) §aDie Verbindung wurde hergestellt.");
- onReconnectScheduler();
- }
- catch (SQLException e)
- {
- Bukkit.getConsoleSender().sendMessage("§8(§e§lMySQL§8) §cDie Verbindung konnte nicht hergestellt werden.");
- System.err.println(e);
- }
- }
- public static boolean hasConnection()
- {
- return con != null;
- }
- public static void close()
- {
- try
- {
- if (con != null)
- {
- con.close();
- con = null;
- Bukkit.getConsoleSender().sendMessage("§8(§e§lMySQL§8) §2Die Verbindung wurde erfolgreich getrennt.");
- }
- }
- catch (SQLException e)
- {
- Bukkit.getConsoleSender().sendMessage("§8(§e§lMySQL§8) §cEs gab ein Fehler bei der abschlie§ung");
- System.err.println(e);
- }
- }
- public static void update(String qry)
- {
- try
- {
- Statement stmt = con.createStatement();
- stmt.executeUpdate(qry);
- }
- catch (Exception e)
- {
- System.err.println(e);
- }
- }
- public static PreparedStatement getStatement(String sql)
- {
- if (hasConnection()) {
- try
- {
- return (PreparedStatement)con.prepareStatement(sql);
- }
- catch (SQLException e)
- {
- try
- {
- con = DriverManager.getConnection("jdbc:mysql://" + Main.host + ":3306/" + Main.database + "?autoreconnect=true", Main.user, Main.password);
- }
- catch (SQLException e1)
- {
- e1.printStackTrace();
- }
- e.printStackTrace();
- }
- }
- return null;
- }
- public static ResultSet getResult(String sql)
- {
- if (hasConnection()) {
- try
- {
- PreparedStatement ps = getStatement(sql);
- return ps.executeQuery();
- }
- catch (SQLException e)
- {
- try
- {
- con = DriverManager.getConnection("jdbc:mysql://" + Main.host + ":3306/" + Main.database + "?autoreconnect=true", Main.user, Main.password);
- }
- catch (SQLException e1)
- {
- e1.printStackTrace();
- }
- e.printStackTrace();
- }
- }
- return null;
- }
- public static Connection getConnection()
- {
- return con;
- }
- public static void createTable()
- {
- if (hasConnection()) {
- try
- {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Melone_Bans (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Wann VARCHAR(100), Grund VARCHAR(100), Banner VARCHAR(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Melone_Mutes (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100), Admin VARCHAR(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Melone_Stats (UUID VARCHAR(100), KILLS int, DEATHS int)");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Coins (Spielername VARCHAR(100), UUID VARCHAR(100), Coins INT(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Spins (Spielername VARCHAR(100), UUID VARCHAR(100), Spins INT(100))");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- private static void onReconnectScheduler()
- {
- Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), new Runnable()
- {
- public void run() {}
- }, 432000L, 432000L);
- }
- private static void onReconnect()
- {
- if (con != null) {
- try
- {
- con.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable()
- {
- public void run()
- {
- try
- {
- MySQL.con = DriverManager.getConnection("jdbc:mysql://" + Main.host + ":3306/" + Main.database + "?autoreconnect=true", Main.user, Main.password);
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }, 1L);
- }
- }
- // MYSQL - DATEN //
- public static String host = "localhost";
- public static String user = "MeloneSpieler";
- public static String password = "f9nP31LWyxHiyGS5";
- public static int port = 3306;
- public static String database = "MeloneSpieler";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement