Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.yeah;
- import java.sql.*;
- public abstract class MySQL {
- public static String ip = "QuickMC.net";
- public static String database = "Global";
- public static String user = "Global";
- public static String password = "av7Gs_01";
- public static String port = "3306";
- public static String prefix = "[StatsAPI] ";
- public static String table = getTable();
- static Connection con;
- public static void connect() {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + ip + ":" + port + "/" + database + "?autoReconnect=true", user, password);
- System.out.println(prefix + "Die Verbindung zur MySQL-Datenbank wurde hergestellt!");
- } catch (SQLException e) {
- System.err.println(prefix + "Die Verbindung zur MySQL-Datenbank ist fehlgeschlagen! Fehler: " + e.getMessage());
- }
- }
- public static void disconnect() {
- try {
- if (con != null) {
- con.close();
- System.out.println(prefix + "Die Verbindung zur MySQL-Datenbank wurde erfolgreich beendet!");
- }
- } catch (SQLException e) {
- System.out.println(prefix + "Fehler beim beenden der Verbindung zur MySQL-Datenbank! Fehler: " + e.getMessage());
- }
- }
- public static void update(String qry) {
- try {
- PreparedStatement ps = con.prepareStatement(qry);
- ps.executeUpdate();
- } catch (SQLException e) {
- System.err.println(prefix + "Fehler beim Updaten: " + e.getMessage());
- }
- }
- public static ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement st = con.createStatement();
- rs = st.executeQuery(qry);
- } catch (SQLException e) {
- connect();
- System.err.println(prefix + "Fehler bei Querybenutzung: " + e.getMessage());
- }
- return rs;
- }
- public static String getTable() {
- if (StatsAPI.status == Modus.FreeForAll) {
- String table = "FFAStats";
- return table;
- }
- if (StatsAPI.status == Modus.SurvivalGames) {
- String table = "SGStats";
- return table;
- }
- if (StatsAPI.status == Modus.JumpWars) {
- String table = "JWStats";
- return table;
- }
- if (StatsAPI.status == Modus.Maze) {
- String table = "MStats";
- return table;
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement