Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.event.Listener;
- public class Connector implements Listener {
- public static String host = "127.0.0.1";
- public static String port = "3306";
- public static String database = "MCN";
- public static String user = "";
- public static String password = "";
- public static Connection con;
- public static void connect() {
- if (!isConnected()) {
- try {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("MySQL Connected.");
- con = DriverManager.getConnection(
- "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", user, password);
- createTable();
- createTableSP();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void disconnect() {
- if (isConnected()) {
- try {
- con.close();
- System.out.println("[EgoPvP] Verbindung Getrennt!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected() {
- return con != null;
- }
- public static void createTable() {
- if (isConnected()) {
- try {
- con.createStatement()
- .executeUpdate("CREATE TABLE IF NOT EXISTS Gems (UUID VARCHAR(100), Gems Int(10))");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void createTableSP() {
- if (isConnected()) {
- try {
- con.createStatement()
- .executeUpdate("CREATE TABLE IF NOT EXISTS Spieler (Anzahl INT(10))");
- Methods_Anzahl.addlist();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void update(String qry) {
- if (isConnected()) {
- try {
- con.createStatement().executeUpdate(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;
- }
- public static Connection getConnection() {
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement