Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private String url_base, host, name, username, password, table;
- private Connection connection;
- public MysqlDatabase(String url_base, String host, String name, String username, String password, String table) {
- this.url_base = url_base;
- this.host = host;
- this.name = name;
- this.username = username;
- this.password = password;
- this.table = table;
- }
- public void connection(){
- if (!isConnected()) {
- try{
- connection = DriverManager.getConnection(url_base + host + "/" + name, username, password);
- }catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void deconnection() {
- if (isConnected()) {
- try {
- connection.close();
- }catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public boolean isConnected() {
- try{
- if((connection == null) || (connection.isClosed() || (!connection.isValid(5)))) {
- return false;
- }else{
- return true;
- }
- }catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- private Connection getConnection(){
- return connection;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement