title: How to deal with EmptyResultDataAccessException when using JdbcTemplate to retrieve data from database?
body: <p>I am getting below exception when I am going to retrieve data which does not exist in database. I am working with spring and using JdbcTemplate to do this. I want to get null in this situation. Can anybody give me a solution for this problem?</p>
  
  <pre><code>Exception in thread "main" org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
  at org.springframework.dao.support.DataAccessUtils.requiredSingleResult(DataAccessUtils.java:71)
  at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:806)
  at com.hojat.LibSpringMVCProject.DAO.BookDAO.getBookById(BookDAO.java:24)
  at com.hojat.LibSpringMVCProject.service.BookService.getBookById(BookService.java:24)
  at com.hojat.LibSpringMVCProject.service.TestService.main(TestService.java:37)
  </code></pre>