· 8 years ago · Jan 02, 2018, 06:30 PM
1package de.becensored.carpus.skywars.mysql;
2
3import java.sql.Connection;
4import java.sql.DriverManager;
5import java.sql.ResultSet;
6import java.sql.SQLException;
7import java.sql.Statement;
8
9import org.bukkit.Bukkit;
10
11public class MySQL {
12
13 /*
14 * MySQL Class by beCensored - Max
15 * Written in 2017
16 * Copying is forbidden
17 */
18
19 public static String Prefix = "[MySQL] ";
20
21 public static String username = "-";
22 public static String password = "-";
23 public static String database = "-";
24 public static String host = "-";
25 public static String port = "-";
26 public static Connection con;
27
28 public MySQL(String user, String pass, String host2, String dB) {
29 }
30
31 public static void connect() {
32 if (!isConnected()) {
33 try {
34 con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username,
35 password);
36 Bukkit.getConsoleSender().sendMessage(Prefix+"MySQL connected");
37 } catch (SQLException e) {
38 e.printStackTrace();
39 }
40 }
41 }
42
43 public static void close() {
44 if (isConnected()) {
45 try {
46 con.close();
47 Bukkit.getConsoleSender().sendMessage(Prefix+"MySQL disconnected");
48 } catch (SQLException e) {
49 e.printStackTrace();
50 }
51 }
52 }
53
54 public static boolean isConnected() {
55 return con != null;
56 }
57
58 public static void createTable() {
59 if (isConnected()) {
60 try {
61 con.createStatement().executeUpdate(
62 "CREATE TABLE IF NOT EXISTS CoinsAPI (UUID VARCHAR(100), KILLS int, DEATHS int , WIN int , LOSE int , COINS int)");
63 Bukkit.getConsoleSender().sendMessage(Prefix+"MySQL Table created");
64 } catch (SQLException e) {
65 e.printStackTrace();
66 }
67 }
68 }
69
70 public static void update(String qry) {
71 if (isConnected()) {
72 try {
73 con.createStatement().executeUpdate(qry);
74 } catch (SQLException e) {
75 e.printStackTrace();
76 }
77 }
78 }
79
80 public static ResultSet getResult(String qry) {
81 ResultSet rs = null;
82 try {
83 Statement st = con.createStatement();
84 rs = st.executeQuery(qry);
85 } catch (SQLException e) {
86 connect();
87 System.err.println(e);
88 }
89 return rs;
90 }
91
92}