Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.Opticzz.endi.MySQL;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.Bukkit;
- import de.Opticzz.endi.Main.Main;
- public class MySQL {
- public static String username;
- 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, username, password);
- Bukkit.getConsoleSender().sendMessage(Main.prefix + "MySQL verbunden");
- }catch(SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
- public static void close() {
- if(isConnected()) {
- try {
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- Bukkit.getConsoleSender().sendMessage(Main.prefix + "MySQL geschlossen");
- }
- }
- public static boolean isConnected() {
- return con != null;
- }
- public static void createTable() {
- if(isConnected()) {
- try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Stats (UUID VARCHAR(100), Name VARCHAR(16) , Stones VARCHAR(1000),Lose VARCHAR(10000))");
- } catch(SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
- public static void update(String qry) {
- if(isConnected()) {
- try {
- con.createStatement().executeUpdate(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getRsult(String qry) {
- if(isConnected()) {
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- public static Connection getCon() {
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement