M
M
Maks Burkov2017-03-24 21:18:43
Spring
Maks Burkov, 2017-03-24 21:18:43

How to get the object correctly using Spring jdbc?

I get an error with this code, why can't I send a request?

Exception in thread "main" org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0

if (object.getClass().equals(Company.class)) {
    Company company = (Company) object;
    String query = "SELECT COMPANY_ID FROM companies WHERE COMPANY_ID = ?";
    return jdbcOperations.queryForObject(query, Long.class, company.getId());
 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
protven, 2017-03-24
@Maks00088

Well, I understand that it is not fashionable to read the documentation, but the error itself clearly enough says what happened.
It is expected that the query will return exactly one value, and it returned 0. Check what you have there in the database.
Pull the request with your hands.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question