Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.yussef.ban.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class MySQL {
- public static String HOST = "";
- public static String PORT = "3306";
- public static String DATABASE = "";
- public static String USERNAME = "";
- public static String PASSWORD = "";
- public static Connection con;
- public static void connect() {
- try {
- if(!(isConnected())) {
- con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":" + PORT + "/" + DATABASE, USERNAME, PASSWORD);
- System.out.print("MySQL Verbunden");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void disconnect() {
- try {
- con.close();
- System.out.print("MySQL ist nun nicht mehr Verbunden");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void update(String qry) {
- try {
- PreparedStatement ps = con.prepareStatement(qry);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static ResultSet getResult(String qry) {
- try {
- PreparedStatement ps = con.prepareStatement(qry);
- return ps.executeQuery();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static boolean isConnected() {
- return (con == null ? false : true);
- }
- public static void createTable() {
- if(isConnected()) {
- MySQL.update("CREATE TABLE IF NOT EXISTS BanSystem (Playername VARCHAR(100), UUID VARCHAR(100), Reason VARCHAR(100))");
- }
- }
- public Connection getConnection() {
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement