public ArrayList<Account> getAccountList() { Connection connect = null; try { ArrayList<Account> accounts = new ArrayList<>(); connect = DBConnection.getConnection(); String sql = "SELECT * FROM account" + "ORDER BY name desc"; ResultSet result = Utility.queryOperation(connect, sql); Account temp = new Account(); while (result.next()) { temp.setName(result.getString("name")); temp.setEmail(result.getString("email")); temp.setSecondaryEmail(result.getString("secondaryEmail")); temp.setTypeAccount(result.getString("typeAccount")); temp.setPassword(result.getString("password")); temp.setAdmin(result.getBoolean("isAdministrator")); accounts.add(temp); } return accounts; } catch (SQLException ex) { Logger.getLogger(AccountManager.class.getName()).log(Level.SEVERE, null, ex); } finally { DBConnection.releaseConnection(connect); } return null; }
public ArrayList<Account> searchUser(String search, String type) throws SQLException { Connection connect = null; ArrayList<Account> accounts; String sql = "SELECT * from account WHERE " + "name LIKE '%" + search + "%'" + "AND typeAccount = '" + type + "'"; String sql2 = "SELECT * from account WHERE " + "typeAccount ='" + type + "'"; try { connect = DBConnection.getConnection(); accounts = new ArrayList<>(); if (search.isEmpty()) { ResultSet result = Utility.queryOperation(connect, sql2); Account temp = new Account(); while (result.next()) { temp.setName(result.getString("name")); temp.setEmail(result.getString("email")); temp.setSecondaryEmail(result.getString("secondaryEmail")); temp.setTypeAccount(result.getString("typeAccount")); temp.setPassword(result.getString("password")); temp.setAdmin(result.getBoolean("isAdministrator")); accounts.add(temp); } } else { ResultSet result = Utility.queryOperation(connect, sql); Account temp = new Account(); while (result.next()) { temp.setName(result.getString("name")); temp.setEmail(result.getString("email")); temp.setSecondaryEmail(result.getString("secondaryEmail")); temp.setTypeAccount(result.getString("typeAccount")); temp.setPassword(result.getString("password")); temp.setAdmin(result.getBoolean("isAdministrator")); accounts.add(temp); } } } finally { DBConnection.releaseConnection(connect); } return accounts; }