Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ---------------------------------------
- * Copyright @RoyalByte | Adrian Schiel
- * Youtube : RoyalByte Developer
- * Skype: RoyalByte
- * Website: RoyalByte.net
- * ---------------------------------------
- */
- package net.royalbyte.cores.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class MySQL {
- public static String host;
- public static String username;
- public static String database;
- public static String password;
- public static int port;
- public static Connection con;
- public static boolean aktiv;
- public static String getMySQLEnabledMSG() {
- if(aktiv) {
- return "§aAktiviert";
- }else {
- return "§cDeaktiviert";
- }
- }
- public static void connect() {
- if (!isConnected()) {
- try {
- con = DriverManager.getConnection(
- "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username,
- password);
- System.out.println("Die §2MySQL §awurde verbunden.");
- } catch (SQLException e) {
- System.out.println("Konnte §4MySQL §cnicht verbinden.");
- }
- }
- }
- public static void close() {
- if (isConnected()) {
- try {
- con.close();
- System.out.println("Die §2MySQL §awurde geschlossen.");
- } catch (SQLException e) {
- System.out.println("Konnte §4MySQL §cnicht beenden.");
- }
- }
- }
- public static boolean isConnected() {
- return con != null;
- }
- public static void update(String qry)
- {
- try
- {
- Statement st = con.createStatement();
- st.executeUpdate(qry);
- st.close();
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- }
- public static ResultSet getResult(String qry) {
- ResultSet rs = null;
- try
- {
- Statement st = con.createStatement();
- rs = st.executeQuery(qry);
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- return rs;
- }
- public static void createTable() {
- update("CREATE TABLE IF NOT EXISTS Stats (Name VARCHAR(16), UUID VARCHAR(100), points INT(100), wins INT(100) , loses INT(100), played_games INT(100), kills INT(100), deaths INT(100), beacons INT(100));");
- }
- }
Add Comment
Please, Sign In to add comment