Advertisement
Guest User

Untitled

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