SHARE
TWEET

Untitled

a guest Oct 4th, 2017 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MySQL
  2. {
  3.  
  4.     private static Connection conn;
  5.  
  6.  
  7.     public void  connect(String host, String database, int port, String user, String password){
  8.         if(!isConnected()){
  9.             try {
  10.                 conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
  11.             } catch (SQLException e) {
  12.                 e.printStackTrace();
  13.                 System.out.println("[SkyWarStats] Errore con il database");
  14.             }
  15.         }
  16.     }
  17.  
  18.     public  void  disconnect(){
  19.         if(isConnected()){
  20.             try {
  21.                 conn.close();
  22.             }catch (SQLException e){
  23.                 e.printStackTrace();
  24.             }
  25.         }
  26.     }
  27.  
  28.     public boolean isConnected(){
  29.         try{
  30.             if((conn == null) || (conn.isClosed()) || (conn.isValid(5))){
  31.                 return false;
  32.             }
  33.             return true;
  34.         }catch(SQLException e){
  35.             e.printStackTrace();
  36.         }
  37.         return false;
  38.     }
  39.  
  40.     public static Connection getConnection(){
  41.         return conn;
  42.     }
  43.  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top