Advertisement
Guest User

Untitled

a guest
Apr 7th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package me.gamergameyt.BanManager.MySQL;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. public class MySQL {
  9.     public static String host;
  10.     public static String port;
  11.     public static String database;
  12.     public static String username;
  13.     public static String password;
  14.     public static Connection con;
  15.    
  16.    
  17.     public static void connect(){
  18.         if(!isConnected()){
  19.             try {
  20.                 con= DriverManager.getConnection("jdbc:mysql://" + host +":" +port +"/" +database, username,password);
  21.                 System.out.println("[MySQL] ist nun Verbunden");
  22.             } catch (SQLException e) {
  23.                 e.printStackTrace();
  24.             }
  25.         }
  26.     }
  27.     public static void disconnect(){
  28.         if(isConnected())
  29.             try {
  30.                 con.close();
  31.                 System.out.println("[MySQL] ist nun nicht mehr Verbunden");
  32.             } catch (SQLException e) {
  33.                 e.printStackTrace();
  34.             }
  35.     }
  36.     public static boolean isConnected(){
  37.         return (con == null ? false : true);
  38.     }
  39.     public static Connection getConnection(){
  40.         return con;
  41.     }
  42.    
  43.     public static void createTable(){
  44.         if(isConnected()){
  45.         try {
  46.             con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BannedPlayers (Spielername VARCHAR(100), UUID VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100))");
  47.         } catch (SQLException e) {
  48.            
  49.             e.printStackTrace();
  50.         }
  51.     }
  52.     }
  53.     public static void update(String qry){
  54.         if(isConnected()){
  55.             try {
  56.                 con.createStatement().executeUpdate(qry);
  57.             } catch (SQLException e) {
  58.                
  59.                 e.printStackTrace();
  60.             }
  61.         }
  62.     }
  63.     public static ResultSet getResult(String qry){
  64.         if(isConnected()){
  65.             try{
  66.         return  con.createStatement().executeQuery(qry);
  67.         }catch (SQLException e){
  68.             e.printStackTrace();
  69.         }
  70.     }
  71.         return null;
  72.     }
  73.    
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement