· 6 years ago · Jun 13, 2019, 10:12 PM
1import me.pluginexception.api.SpigotCore;
2import org.bukkit.Bukkit;
3
4import java.sql.Connection;
5import java.sql.PreparedStatement;
6import java.sql.SQLException;
7
8public class SQLManager {
9 private final SpigotCore plugin;
10 private final ConnectionPoolManager pool;
11
12 public SQLManager(SpigotCore plugin) {
13 this.plugin = plugin;
14 pool = new ConnectionPoolManager(plugin);
15 makeTable();
16 Bukkit.getConsoleSender().sendMessage("Hikari MySQL Connection succesfull.");
17 }
18
19 private void makeTable() {
20 Connection conn = null;
21 PreparedStatement ps = null;
22 try {
23 conn = pool.getConnection();
24 ps = conn.prepareStatement(
25 "CREATE TABLE IF NOT EXISTS `Test` " +
26 "(" +
27 "UUID varchar(30)" +
28 ")"
29 );
30 ps.executeUpdate();
31 } catch (SQLException e) {
32 e.printStackTrace();
33 } finally {
34 pool.close(conn, ps, null);
35 }
36 }
37
38 public void onDisable() {
39 pool.closePool();
40 }