I do a simple web-app where user can select checkboxes of items to remove them from database(like mail manager).
So, is there a correct way to do this?
I think to do like this:(in DAO class)
void delete(List<Long> ids){
.....
statement = connection.prepareStatement("DELETE FROM table WHERE id=?");
for (Long id: ids){
statement.setInt(1, id);
statement.executeUpdate();
}
......
or this:(in servlet action class)
DAO dao = new DAO();
for (Long id: ids){
dao.delete(id); // in DAO simple method void delete(long id);
}
are not good. Сan you tell or explain how to do it right?
UPDATE: ok, can someone tell me how to delete records not one by one?