· 6 years ago · Dec 03, 2019, 11:56 PM
1package me.SymNet.Report;
2
3
4import java.sql.Connection;
5import java.sql.DriverManager;
6import java.sql.SQLException;
7import java.sql.Statement;
8
9
10
11public class MySQL {
12
13 public static void load() {
14
15 try {
16 Class.forName("com.mysql.jdbc.Driver");
17 } catch (ClassNotFoundException e) {
18 e.printStackTrace();
19 System.err.println("Driver jdbc non disponibile!");
20 return;
21 }
22
23 try {
24 String query = "CREATE TABLE IF NOT EXISTS SymReport ( 'ID' integer primary key autoincrement , 'Giocatore' VARCHAR(100) , 'GiocatoreReportato' VARCHAR(100) , 'Motivo' VARCHAR(1000) , 'Data' DATE NOT NULL DEFAULT CURRENT_TIMESTAMP ) Engine = 'InnoDB';";
25 openConnection();
26 try {
27 Main.connection.createStatement().execute(query);
28 } catch (SQLException e) {
29 e.printStackTrace();
30 }
31
32 } catch (ClassNotFoundException e) {
33 e.printStackTrace();
34 } catch (SQLException e) {
35 e.printStackTrace();
36 }
37
38
39 }
40
41
42 public static void openConnection() throws SQLException, ClassNotFoundException {
43 if (Main.connection != null && !Main.connection.isClosed()) {
44 return;
45 }
46 Class.forName("com.mysql.jdbc.Driver");
47 Main.connection = DriverManager.getConnection("jdbc:mysql://" + Main.host+ ":" + Main.port + "/" + Main.database + "?useSSL="+Main.SSL, Main.user, Main.password);
48 }
49
50
51}