package aronsodb; import java.sql.*; public class DatabaseHandler { private Connection connection; private String host; private String username; private String password; private String database; public DatabaseHandler(String host, String username, String password, String database) { this.host = host; this.username = username; this.password = password; this.database = database; this.loadDriver(); this.loadConnection(); } private void loadDriver() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception ex) { ex.printStackTrace(); } } private void loadConnection() { try { this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":3306/" + this.database + "?user=" + this.username + "&password=" + this.password); } catch (SQLException ex) { ex.printStackTrace(); } } public ResultSet executeQuery(String query) { try { Statement statement = this.connection.createStatement(); return statement.executeQuery(query); } catch (SQLException ex) { ex.printStackTrace(); } return null; } }