The question is pretty much summed up in the title. What will JdbcTemplate.queryForList() return when the query returns no results. Will it return an empty List or null value? I couldn't find a definitive answer from the documentation. Thanks in advance!
queryForList(sql); JdbcTemplate's queryForList() method returns a list of rows from the table.
Clearly, if the RowMapper returns null, null will be added to the list. Since ArrayList permits null elements, this will return a list with nulls in it.
In Java's Spring framework, we can use jdbcTemplate. queryForObject() to get a single row record from the database, and convert the row into an object (i.e. POJO or your entity class) via the row mapper feature. Java's Spring framework provides class, which is most useful and also Recommended.
Set the query timeout for statements that this JdbcTemplate executes. Default is 0, indicating to use the JDBC driver's default. Note: Any timeout specified here will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.
The javadoc states that it will return
a List of objects that match the specified element type
If there's no element, the list is empty.
It will return an empty list. So you can test it with list.isEmpty()
. It will return true in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With