· 8 years ago · Jun 11, 2018, 08:52 PM
1public void CreateTable(){
2 String table = ("CREATE TABLE IF NOT EXISTS `table1` (`ID` INT(255) NOT NULL AUTO_INCREMENT, `Value1` varchar(16) NOT NULL, PRIMARY KEY (`ID`))");
3 Connection conn = null;
4 Statement st = null;
5 try{
6 conn = getSQLConn();
7 }catch(SQLException SQLE){
8 log.log(Level.SEVERE, "[Plugin] - SQL Exception setting Connection ", SQLE);
9 }
10 if(conn != null){ //Dont wanna try executing if the connection isnt set
11 try{
12 st = conn.createStatement(); //Creates MySQL Statement
13 st.executeUpdate(table1); //Creates Table
14 }catch (SQLException SQLE) {
15 log.log(Level.SEVERE, "[Plugin] - SQL Exception creating table ", SQLE);
16 }finally{
17 try{
18 if(st != null && !st.isClosed()){ st.close(); } //Remember to close the connection
19 if(conn != null && !conn.isClosed()){ conn.close(); } //Remember to close the connection
20 }catch(SQLException SQLE){
21 log.log(Level.SEVERE, "[Plugin] - SQL Exception closing connection ", SQLE);
22 }
23 }
24 }
25 }