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