Advertisement
Guest User

Code MySQL

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