Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.byfoxy.main.manager;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import de.byfoxy.main.Main;
- public class MySQL {
- private static String host = Main.instance.getConfig().getString("MySQL.host");
- private static String port = Main.instance.getConfig().getString("MySQL.port");
- private static String user = Main.instance.getConfig().getString("MySQL.user");
- private static String passwort = Main.instance.getConfig().getString("MySQL.password");
- private static String database = Main.instance.getConfig().getString("MySQL.database");
- public static Connection con;
- public static void connect() {
- if (!connected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", user, passwort);
- System.out.println("[ScoreKill] Die MySQL Verbindung wurde aufgebaut.");
- createTable();
- } catch (SQLException e) {
- System.out.println("[ScoreKill] Kein Verbindung zum MySQL Server gefunden! ERROR CODE: #1612");
- }
- }
- }
- private static void createTable() {
- if (connected()) {
- PreparedStatement ps = MySQL.getStatement("CREATE TABLE IF NOT EXISTS KillManager (UUID VARCHAR(64), Kills int)");
- try {
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static PreparedStatement getStatement(String sql) {
- if (connected()) {
- try {
- return con.prepareStatement(sql);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- public static boolean connected() {
- return con != null;
- }
- public static void disconnect() {
- if (connected()) {
- try {
- con.close();
- System.out.println("[ScoreKill] Die MySQL Verbindung wurde geschlossen.");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement