0

I'm programming a backend project with spring boot and PostgreSQL. Now i have a problem. I'm trying to program a method that delete an Order from my database:

@Override
public int deleteTaskById(UUID id) {
    final String sql = "DELETE FROM task WHERE id = ?";
    Task task = jdbcTemplate.queryForObject(
            sql,
            new Object[]{id},
            (resultSet, i) -> {
                UUID taskId = UUID.fromString(resultSet.getString("id"));
                String name = resultSet.getString("name");
                return new Task(taskId, name);
            });
    return 0;
}

The order will be deleted but i get always the exception

org.postgresql.util.PSQLException: The query gave no result.

Postman gives me this exception:

{
    "timestamp": "2020-03-10T09:34:45.279+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "PreparedStatementCallback; SQL [DELETE FROM task WHERE id = ?]; The query gave no result.; nested exception is org.postgresql.util.PSQLException: The query gave no result.",
    "path": "/api/task/2e7b278d-4610-46ef-875c-d3667b5fa0a4"
}
Bashir
  • 2,057
  • 5
  • 19
  • 44
Yuto
  • 148
  • 1
  • 2
  • 11
  • 2
    You need to use update() for anything that does not return a resultset. Read the [JavaDocs](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html#update-java.lang.String-) – jose praveen Mar 10 '20 at 09:44
  • Possible duplicate https://stackoverflow.com/questions/21276059/no-results-returned-by-the-query-error-in-postgresql – IMParasharG Mar 10 '20 at 09:46

0 Answers0