Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.slixfx.slixstats.utils;
- import de.slixfx.slixstats.main.Main;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Arrays;
- /**
- * Created by SlixFX on 11.07.2017 with Heart <3.
- */
- public class MySQL {
- public static String username;
- public static String password;
- public static String database;
- public static String host;
- public static String port;
- public static Connection con;
- public static void connect() {
- if(!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":"+port+"/" + database, username, password);
- System.out.println(Main.getInstance().prefix + "MySQL Verbindung aufgebaut!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void close() {
- if(isConnected()) {
- try {
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- System.out.println(Main.prefix + "§aMySQL Verbindung geschlossen!");
- }
- }
- public static boolean isConnected() {
- return con != null;
- }
- public static void createTables() {
- if(!isConnected()) {
- System.out.println(Main.prefix+"§cMySQL-Verbindung besteht nicht, versuche neu zu verbinden");
- connect();
- }
- try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS connections (Name VARCHAR(60), UUID VARCHAR(36), IP INT UNSIGNED, Server VARCHAR(100), Unixtime BIGINT, Date VARCHAR(22), Playerstate TINYINT(1), Type TINYINT(1))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS onlineplayers (Name VARCHAR(60), UUID VARCHAR(36), Server VARCHAR(100), Playerstate TINYINT(1))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS commands (Name VARCHAR(60), UUID VARCHAR(36), IP INT USIGNED, Server VARCHAR(100), Command VARCHAR(100), Permission VARCHAR(100), Server VARCHAR(100), World VARCHAR(40), X INT, Y INT, Z INT, Playerstate TINYINT(1), OP TINYINT(1), Unixtime BIGINT, Date VARCHAR(22))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS playtime (Name VARCHAR(60), UUID VARCHAR(36), Server VARCHAR(100), Playtime BIGINT UNSIGNED, Afktime BIGINT UNSIGNED)");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS chat (Name VARCHAR(60), UUID VARCHAR(36), Server VARCHAR(100), World VARCHAR(40), X INT, Y INT, Z INT , Message VARCHAR(100), Unixtime BIGINT, Date VARCHAR(22), Playerstate TINYINT(1))");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void update(String qry) {
- if(!isConnected()) {
- System.out.println(Main.prefix+"§cMySQL-Verbindung besteht nicht, versuche neu zu verbinden");
- connect();
- return;
- }
- try {
- con.createStatement().executeUpdate(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static ResultSet getResult(String qry) {
- if(!isConnected()) {
- System.out.println(Main.prefix+"§cMySQL-Verbindung besteht nicht, versuche neu zu verbinden");
- connect();
- }
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement