Answer the question
In order to leave comments, you need to log in
Why is there an error in sql query?
I am trying to delete a row from a table by id
public void deleteFilmsOlderGivenYears(int givenYears, Statement st) throws SQLException {
for (Film a : films) { //перебираю коллекцию кино
int dataRelease = Integer.parseInt(a.getDate_release().substring(0, 4)); //формирую дату
if (dataRelease < givenYears) { //нахожу нужную дату
st.executeQuery("DELETE FROM films WHERE id =" + a.getId()); //пытаюсь удалить кино по ID
}
}
}
Answer the question
In order to leave comments, you need to log in
You need to call executeUpdate, not executeQuery. And by the way, what's the point of running database queries in a loop?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question