Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.juliangames.bungee.sql;
- import net.md_5.bungee.*;
- import net.md_5.bungee.api.chat.*;
- import java.sql.*;
- import java.io.*;
- import net.md_5.bungee.config.*;
- 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 {
- MySQL.con = DriverManager.getConnection("jdbc:mysql://" + MySQL.host + ":" + MySQL.port + "/" + MySQL.database + "?autoReconnect=true", MySQL.username, MySQL.password);
- BungeeCord.getInstance().getConsole().sendMessage((BaseComponent)new TextComponent("§8============================================================"));
- BungeeCord.getInstance().getConsole().sendMessage((BaseComponent)new TextComponent("§7Status: §aDie MySQL Verbindung wurde erfolgreich aufgebaut."));
- BungeeCord.getInstance().getConsole().sendMessage((BaseComponent)new TextComponent("§8============================================================"));
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void close() {
- if (isConnected()) {
- try {
- MySQL.con.close();
- BungeeCord.getInstance().getConsole().sendMessage((BaseComponent)new TextComponent("§8============================================================"));
- BungeeCord.getInstance().getConsole().sendMessage((BaseComponent)new TextComponent("§7Status: §cDie MySQL Verbindung wurde erfolgreich geschlossen."));
- BungeeCord.getInstance().getConsole().sendMessage((BaseComponent)new TextComponent("§8============================================================"));
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected() {
- return MySQL.con != null;
- }
- public static void update(final String query) {
- PreparedStatement ps = null;
- try {
- ps = MySQL.con.prepareStatement(query);
- ps.executeUpdate();
- }
- catch (SQLException e) {
- e.printStackTrace();
- try {
- ps.close();
- }
- catch (SQLException e1) {
- e.printStackTrace();
- }
- }
- finally {
- try {
- ps.close();
- }
- catch (SQLException e2) {
- e2.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(final String query) {
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- ps = MySQL.con.prepareStatement(query);
- rs = ps.executeQuery();
- return rs;
- }
- catch (SQLException e) {
- e.printStackTrace();
- return null;
- }
- }
- public static void createTables() {
- if (isConnected()) {
- try {
- MySQL.con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BannedPlayers (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100), Banner VARCHAR(100))");
- MySQL.con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS MutedPlayers (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100), MUTER VARCHAR(100))");
- MySQL.con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS OnlineTime (Spielername VARCHAR(100), UUID VARCHAR(100), Zeit INT(100))");
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void loadFile() {
- try {
- final File file = new File("plugins//PC-Bungee", "MySQL.yml");
- boolean created = true;
- if (!file.exists()) {
- file.createNewFile();
- created = false;
- }
- final Configuration config = ConfigurationProvider.getProvider((Class)YamlConfiguration.class).load(file);
- if (!created) {
- config.set("mysql.Host", (Object)"91.218.67.112");
- config.set("mysql.Port", (Object)"3306");
- config.set("mysql.Database", (Object)"PC-Systeme");
- config.set("mysql.Username", (Object)"pandora");
- config.set("mysql.Password", (Object)"Quanitesedisitu");
- ConfigurationProvider.getProvider((Class)YamlConfiguration.class).save(config, file);
- }
- MySQL.host = config.getString("mysql.Host");
- MySQL.port = config.getString("mysql.Port");
- MySQL.database = config.getString("mysql.Database");
- MySQL.username = config.getString("mysql.Username");
- MySQL.password = config.getString("mysql.Password");
- }
- catch (Exception ex) {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement