1
votes

I am calling below method by passing value to a.

public Sample get(String a) {
    return jdbcTemplate.queryForObject(SQL, new Object[] { a }, rowMapper);
}

On execute of the below queryForObject method, it throws exception

"EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0" and object array value be null. public T queryForObject(String sql, Object[] args, RowMapper rowMapper) throws DataAccessException { List results = query(sql, args, new RowMapperResultSetExtractor(rowMapper, 1)); return DataAccessUtils.requiredSingleResult(results); }

2

2 Answers

3
votes

Your query didn't return a result.

Two solutions :

  • fix your query to always return a result
  • try/catch EmptyResultDataAccessException and choose the appropriate behavior
1
votes

Just to clarify more, by my recent experience -> it clearly mentions: "EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0" which means it is expecting only 1 row, as a result of your SQL query execution, not 0 and not more than 1. So, make sure execution of your SQL query results in only one row.