title: Null Pointer Exception while using jdbcTemplate in Spring 3.0
body: <p>This is what I have tried so far.<br>
  DaoImpl.java</p>
  
  <pre><code>@Component
  public class DaoImpl {
    @Autowired
    private DataSource dataSource;
    private JdbcTemplate jdbcTemplate;
  
    public DataSource getDataSource() {
      return dataSource;
    }
  
    public void setDataSource(DataSource dataSource) {
      this.jdbcTemplate = new JdbcTemplate(dataSource);
        }
  
    public JdbcTemplate getJdbcTemplate() {
      return jdbcTemplate;
    }
  
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
      this.jdbcTemplate = jdbcTemplate;
    }
  
    public int getCircleCount() {
      String sql = "select count(*) from circle";
      return (Integer)getJdbcTemplate().queryForObject(sql, Integer.class); //throws NPE
      //return getJdbcTemplate().queryForInt(sql);
    }
  }
  </code></pre>
  
  <p>spring.xml</p>
  
  <pre><code>&lt;bean id="dataSource"
      class="org.apache.commons.dbcp2.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" /&gt;
      &lt;property name="url" value="jdbc:derby://localhost:1527/db" /&gt;
      &lt;property name="initialSize" value="2"/&gt;
      &lt;property name="maxTotal" value="5"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>But I'm getting Null Pointer Exception at return statement of getCircleCount().
  I'm learning Spring JDBC. Please help.</p>