· 10 years ago · Jul 01, 2016, 07:48 PM
1package MySQL;
2
3import java.sql.Connection;
4import java.sql.DriverManager;
5import java.sql.SQLException;
6
7public class SQL {
8
9 public static SQL sql;
10 public String host,database,username,password;
11 public int port;
12 public Connection conn;
13
14 public void Connect() {
15 this.host = "null";
16 this.port = 3306;
17 this.database = "null";
18 this.username = "null";
19 this.password = "null";
20
21 try {
22 this.conn = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
23 this.conn.prepareStatement( "CREATE TABLE IF NOT EXISTS TABLE_NAME (PLAYER varchar(16), ID varchar(100), STATE integer(1))" ).execute();
24 } catch (Exception ex) {
25 }
26 }
27 public void Disconnect() {
28 if(this.conn != null)
29 try {
30 this.conn.close();
31 } catch (Exception e) {
32 this.conn = null;
33 }
34 }
35 public void checkConnection() {
36 try {
37 if(this.conn == null | this.conn.isClosed())
38 Connect();
39 } catch (SQLException ex) {
40 Connect();
41 }
42 }
43 public static SQL get() {
44 if(sql == null) sql = new SQL();
45 return sql;
46 }
47}