public class MySQL { private MobTokens instance; private Connection connection; public MySQL(MobTokens instance) { this.instance = instance; } public boolean isConnected() { return (connection != null); } public boolean connect() { if (!isConnected()) { try { String host = instance.getConfig().getString("database.host"); String port = instance.getConfig().getString("database.port"); String database = instance.getConfig().getString("database.database"); String username = instance.getConfig().getString("database.username"); String password = instance.getConfig().getString("database.password"); connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?useSSL=false", username, password); } catch (SQLException e) { e.printStackTrace(); return false; } } return true; } public void disconnect() { if (isConnected()) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } public Connection getConnection() { return connection; } }