SHARE
TWEET

Untitled

a guest Aug 13th, 2019 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package de.yussef.ban.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9. public class MySQL {
  10.    
  11.     public static String HOST = "";
  12.     public static String PORT = "3306";
  13.     public static String DATABASE = "";
  14.     public static String USERNAME = "";
  15.     public static String PASSWORD = "";
  16.     public static Connection con;
  17.    
  18.    
  19.     public static void connect() {
  20.         try {
  21.             if(!(isConnected())) {
  22.                 con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":" + PORT + "/" + DATABASE, USERNAME, PASSWORD);
  23.                 System.out.print("MySQL Verbunden");
  24.             }
  25.         } catch (SQLException e) {
  26.             e.printStackTrace();
  27.         }
  28.     }
  29.  
  30.     public static void disconnect() {
  31.         try {
  32.             con.close();
  33.             System.out.print("MySQL ist nun nicht mehr Verbunden");
  34.         } catch (SQLException e) {
  35.             e.printStackTrace();
  36.         }
  37.     }
  38.  
  39.     public static void update(String qry) {
  40.         try {
  41.             PreparedStatement ps = con.prepareStatement(qry);
  42.             ps.executeUpdate();
  43.         } catch (SQLException e) {
  44.             e.printStackTrace();
  45.         }
  46.     }
  47.  
  48.     public static ResultSet getResult(String qry) {
  49.         try {
  50.             PreparedStatement ps = con.prepareStatement(qry);
  51.             return ps.executeQuery();
  52.         } catch (SQLException e) {
  53.             e.printStackTrace();
  54.         }
  55.         return null;
  56.     }
  57.  
  58.     public static boolean isConnected() {
  59.         return (con == null ? false : true);
  60.     }
  61.  
  62.     public static void createTable() {
  63.         if(isConnected()) {
  64.             MySQL.update("CREATE TABLE IF NOT EXISTS BanSystem (Playername VARCHAR(100), UUID VARCHAR(100), Reason VARCHAR(100))");
  65.         }
  66.     }
  67.  
  68.     public Connection getConnection() {
  69.         return con;
  70.     }
  71. }
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