Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySQL
- {
- private static Connection conn;
- public void connect(String host, String database, int port, String user, String password){
- if(!isConnected()){
- try {
- conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
- } catch (SQLException e) {
- e.printStackTrace();
- System.out.println("[SkyWarStats] Errore con il database");
- }
- }
- }
- public void disconnect(){
- if(isConnected()){
- try {
- conn.close();
- }catch (SQLException e){
- e.printStackTrace();
- }
- }
- }
- public boolean isConnected(){
- try{
- if((conn == null) || (conn.isClosed()) || (conn.isValid(5))){
- return false;
- }
- return true;
- }catch(SQLException e){
- e.printStackTrace();
- }
- return false;
- }
- public static Connection getConnection(){
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement