views:

27

answers:

1

What does SimpleJDBCTemplate.queryForInt do when the SQL query's actual result is null?

In particular, what happens if I run queryForInt("select max(foo) from f") and f has no rows?

While I'm on this subject, what happens if I run queryForInt("select foo from f") and f has no rows?

A: 

If the query returns null, the queryForInt method will return 0. However, if the query returns no rows, or returns more than one row, queryForInt will throw an IncorrectResultSizeDataAccessException.

Source

JacobM
Thanks. I ended up using `coalesce` in the query to ensure that the query always returns a sane default value, rather than letting my client use the 0.
Ken Bloom