Advertisement
Guest User

mysql.java

a guest
Jun 4th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package cz.wake.plugins;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.util.logging.Level;
  7.  
  8. import org.bukkit.Bukkit;
  9.  
  10.  
  11. public class MySQL {
  12.    
  13.     private Connection con;
  14.    
  15.     public Connection getCurrentConnection(){
  16.         try{
  17.             if((this.con == null) || (this.con.isClosed())){
  18.                 this.con = DriverManager.getConnection("jdbc:mysql://" + Main.getInstance().getConfig().getString("host") + ":" + Main.getInstance().getConfig().getString("port") + "/" +  Main.getInstance().getConfig().getString("database"), Main.getInstance().getConfig().getString("user"), Main.getInstance().getConfig().getString("password"));
  19.             }
  20.         } catch(SQLException localSQLException){
  21.             localSQLException.printStackTrace();
  22.         }
  23.         return this.con;
  24.     }
  25.    
  26.     public synchronized void closeConnection()
  27.       {
  28.         try
  29.         {
  30.           if ((!this.con.isClosed()) || (this.con != null)) {
  31.             this.con.close();
  32.           }
  33.         }
  34.         catch (SQLException localSQLException)
  35.         {
  36.           localSQLException.printStackTrace();
  37.         }
  38.       }
  39.    
  40.     public synchronized void checkTable()
  41.       {
  42.         try
  43.         {
  44.           getCurrentConnection().createStatement().execute(
  45.             "CREATE TABLE IF NOT EXISTS `CM_levels` (\n`UUID` varchar(36),\n`Level` int(11),\n`Exp` int(11),\n`Karma` int(11),\nPRIMARY KEY  (`UUID`)\n)");
  46.         }
  47.         catch (SQLException localSQLException)
  48.         {
  49.           localSQLException.printStackTrace();
  50.         }
  51.       }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement