· 7 years ago · Feb 24, 2019, 09:24 AM
1public MySQL initialize() {
2
3 Connection connection = Objects.requireNonNull(getConnection(), "SQL Connection is null");
4
5 try {
6 connection.prepareStatement("SELECT 1 FROM members LIMIT 1").executeQuery().close();
7 connection.close();
8 } catch (final SQLException e) {
9 try {
10 PreparedStatement ps = connection.prepareStatement(
11 "CREATE TABLE IF NOT EXISTS `members` (\n" +
12 " `id` int auto_increment primary key,\n" +
13 " `username` text,\n" +
14 " `id_long` bigint\n" +
15 ") ENGINE=InnoDB DEFAULT CHARSET=utf8;"
16 );
17
18 ps.executeBatch();
19 ps.close();
20 connection.close();
21 System.out.println("Helper > Database structure created...");
22 } catch (final SQLException e1) {
23 e1.printStackTrace();
24
25 try {
26 connection.close();
27 } catch (SQLException e2) {
28 e2.printStackTrace();
29 }
30 }
31 }
32
33 return this;
34 }