Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. package fr.scopegames.api.database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class Database {
  8.  
  9. private Connection connection;
  10.  
  11. public void connect(String host, String database, int port, String user, String password){
  12. if(!isConnected()){
  13. try { connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
  14. } catch (SQLException e) { e.printStackTrace(); }
  15. }
  16. }
  17.  
  18. public void disconnect(){
  19. if(isConnected()){
  20. try { connection.close();
  21. } catch (SQLException e) { e.printStackTrace(); }
  22. }
  23. }
  24.  
  25. public boolean isConnected(){
  26. try {
  27. if((connection == null) || (connection.isClosed()) || (connection.isValid(5))) return false;
  28. return true;
  29. } catch (SQLException e) { e.printStackTrace(); } return false;
  30. }
  31.  
  32. public Connection getConnection(){
  33. return connection;
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement