Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.slixfx.slixchat.util;
- import de.slixfx.slixchat.main.Main;
- import java.sql.*;
- /**
- * Created by SlixFX on 06.05.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 + ":3306/" + 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() {
- /**
- * Syntax: Spielername, UUID, Ende, Grund
- */
- if(isConnected()) try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Ranks (Rang VARCHAR(100), Prefix VARCHAR(1000), ChatColor VARCHAR(10))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Players (UUID VARCHAR(100), Name VARCHAR(100), Rang VARCHAR(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS CustomPrefix (UUID VARCHAR(100), Name VARCHAR(100), Prefix VARCHAR(1000), ChatColor VARCHAR(10))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Servers (Server VARCHAR(100), Abkuerzung VARCHAR(10))");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void update(String qry) {
- if(isConnected()) {
- try {
- con.createStatement().executeUpdate(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String qry) {
- if(isConnected()) {
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement