SHARE
TWEET

Untitled

a guest Aug 12th, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package de.EidechsenGHG.QuickSurvivalGames.MySQL;
  2.  
  3. import de.EidechsenGHG.QuickSurvivalGames.Main;
  4. import org.bukkit.Bukkit;
  5.  
  6. import java.sql.*;
  7.  
  8. /**
  9.  * Created by cooki on 12.08.2016.
  10.  */
  11. public class MySQL {
  12.  
  13.     private static String HOST = "localhost";
  14.     private static String DATABASE = "Punkte";
  15.     private static String USERNAME = "root";
  16.     private static String PASSWORD = "fjnif823";
  17.     private static Connection con;
  18.  
  19.     public static void connect() {
  20.         try {
  21.             con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USERNAME, PASSWORD);
  22.             Bukkit.getConsoleSender().sendMessage(Main.prefix + "§aMySQL-Verbindung wurde aufgebaut!");
  23.         } catch (SQLException e) {
  24.             Bukkit.getConsoleSender().sendMessage(Main.prefix + "§cMySQL-Verbindung konnte nicht aufgebaut werden!");
  25.         }
  26.     }
  27.  
  28.     public static void disconnect() {
  29.         try {
  30.             con.close();
  31.             Bukkit.getConsoleSender().sendMessage(Main.prefix + "§aMySQL Verbindung wurde getrennt!");
  32.         } catch (SQLException e) {
  33.             Bukkit.getConsoleSender().sendMessage(Main.prefix + "§cFehler beim schließen der MySQL Datenbank!");
  34.         }
  35.     }
  36.  
  37.     public static void update(String qry) {
  38.         try {
  39.             Statement statement = con.createStatement();
  40.             statement.executeUpdate(qry);
  41.             statement.close();
  42.         } catch (SQLException e) {
  43.             connect();
  44.             System.err.println(e);
  45.         }
  46.     }
  47.  
  48.     public static ResultSet query(String qry) {
  49.         ResultSet resultSet = null;
  50.         try {
  51.             Statement statement = con.createStatement();
  52.             resultSet = statement.executeQuery(qry);
  53.         } catch (SQLException e) {
  54.             connect();
  55.             System.err.println(e);
  56.         }
  57.         return resultSet;
  58.     }
  59.  
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top