Код метода отрабатывает нормально, но еще и выводит "Operation not allowed after ResultSet closed". На stackoverflow есть такее вопросы и они уже решенные. Но я что-то не так делаю, и оно не работает :) Код должен брать количество одного продукта из бд и увеличивать его на то количество, которое напишет пользователь. Как избавиться от "Operation not allowed after ResultSet closed"
Вообщем и целом, вот код:
if (searchedCategory) {
Statement statementUpdate = connection.createStatement();
sql = "select * from snacks where category='" + categoryFromUser + "'";
ResultSet rsUpdate = statementUpdate.executeQuery(sql);
// add an additional amount
while (rsUpdate.next()) {
int amountFromTable = rsUpdate.getInt("amount");
double priceFromTable = rsUpdate.getDouble("price");
String formattedPrice = String.format("%.2f", priceFromTable).replace(",", ".");
int amountRes = amountFromTable + amountFromUser;
sql = "update snacks " +
"set amount=" + amountRes + " where category='" + categoryFromUser + "'";
statementUpdate.executeUpdate(sql);
System.out.println(categoryFromUser + " " + formattedPrice + " " + amountRes);
}
rsUpdate.close();
statementUpdate.close();
} else {
System.out.println("There is no such category in the list :( \n" +
"First, add your \"" + categoryFromUser + "\" using the addCategory command");
}
Как избавиться от "Operation not allowed after ResultSet closed"?