Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.gamechest.bansystem.niroxz.MySQL;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class MySQL
- {
- public static String user;
- public static String password;
- public static String database;
- public static String host;
- public static String port;
- public static Connection con;
- public static void connect() {
- if (!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
- System.out.println("[Ban MySQL] Connecting to: "+host + ":" + port + "/" + database);
- } catch (SQLException e) {
- }
- }
- }
- public static void close() {
- if(isConnected()) {
- try {
- con.close();
- System.out.println("[Ban MySQL] MySQL connection closed!");
- con = null;
- } catch (SQLException e) {
- e.printStackTrace();
- System.err.println("[Ban MySQL] Could not close MySQL connection!");
- }
- }
- }
- public static boolean isConnected()
- {
- return con != null;
- }
- public static void createTable() {
- if (isConnected())
- try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BannedPlayers (id INT auto_increment, Spielername VARCHAR(100), UUID VARCHAR(100), IP VARCHAR(100),Ende VARCHAR(100) , Grund VARCHAR(100), Ersteller VARCHAR(100), PRIMARY KEY(id))");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void update(String qry)
- {
- if (isConnected())
- try {
- con.createStatement().execute(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static ResultSet getResult(String qry)
- {
- if (isConnected()) {
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement