JDBC template throws NullPointerException when no rows found
<p>I have a query to sum numeric values from single column:</p>

<pre><code>int numberOfDays = jdbcTemplate.queryForObject
("select sum(number_of_days) from business_trip where name = ? and surname = ? and type = ?",new Object[]{name,surname,"UE"},Integer.class);
</code></pre>

<p>It works fine as long as there is a business trip of UE category for selected user. Then it sums trip days correctly. However, if there are no trips of UE category, instead of zero I'm getting <strong>NullPointerException</strong>. I can place this line inside try/catch but that would be a workaround. I would like to figure out why NPE is thrown in such case.</p>

<pre><code>*2016-11-24 11:13:02.613 ERROR 8316 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException: null
at com.tfb.dao.BusinessTripDAO.getKrajoweTripsDaysForEmployee(BusinessTripDAO.java:59) ~[classes/:na]*
</code></pre>