Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.scopegames.api.database;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class Database {
- private Connection connection;
- public void connect(String host, String database, int port, String user, String password){
- if(!isConnected()){
- try { connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
- } catch (SQLException e) { e.printStackTrace(); }
- }
- }
- public void disconnect(){
- if(isConnected()){
- try { connection.close();
- } catch (SQLException e) { e.printStackTrace(); }
- }
- }
- public boolean isConnected(){
- try {
- if((connection == null) || (connection.isClosed()) || (connection.isValid(5))) return false;
- return true;
- } catch (SQLException e) { e.printStackTrace(); } return false;
- }
- public Connection getConnection(){
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement