· 5 years ago · Aug 13, 2020, 02:26 PM
1package de.mathematischer.utils;
2
3import java.sql.Connection;
4import java.sql.DriverManager;
5import java.sql.SQLException;
6
7public class MySQL {
8
9 public static Connection connection;
10
11 public static void connect() {
12 if (!isConnected()) {
13 try {
14 connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/waterfight?autoReconnect=true",
15 "root", "");
16 System.out.println("MySQL verbunden");
17 } catch (SQLException e) {
18 e.printStackTrace();
19 }
20 }
21
22 }
23
24 public static void disconnect() {
25 if (isConnected()) {
26 try {
27 connection.close();
28 } catch (SQLException e) {
29 e.printStackTrace();
30 }
31 System.out.println("MySQL getrennt");
32 }
33
34 }
35
36 public static boolean isConnected() {
37 return (connection != null);
38 }
39
40 public static void createTable() {
41 try {
42 connection.prepareStatement(
43 "CREATE TABLE IF NOT EXISTS inventoryStandard (uuid VARCHAR(100), stick INT(16), rod INT(16), snowballs INT(16), enderpearls INT(16)")
44 .executeUpdate();
45 } catch (SQLException e) {
46 e.printStackTrace();
47 }
48 }
49
50}
51