java.lang.NullPointerException

Spring JIRA | Claus Ibsen | 1 decade ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    I am playing with the JdbcTemplate and have the following code: JdbcTemplate jdbc = new JdbcTemplate(); String[] s = (String[]) jdbc.queryForObject(SELECT_SQL, new Object[]{new Long(id)}, java.lang.String[].class); As I do not pass in a datasource to JdbcTemplate and does not call setDataSource on it I get the following NPE. Maybe a check in the code and to throw a propper exception stating somekind of error text that a datasource is not set on the template would be nice instead of a NPE. Just to add to Jurgens/Thomas list of silly TODO's instead of cool new features. java.lang.NullPointerException at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:173) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:152) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:128) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:319) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:374) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:410) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:469) at com.bmd.selfservice.dao.KundeHibernateDAO.loadKundeEmail(KundeHibernateDAO.java:55) at com.bmd.selfservice.KundeBusiness.getKundeEmail(KundeBusiness.java:40) at com.bmd.selfservice.demo.KundeDemo.email(KundeDemo.java:55) at com.bmd.selfservice.demo.KundeDemo.main(KundeDemo.java:62)

    Spring JIRA | 1 decade ago | Claus Ibsen
    java.lang.NullPointerException
  2. 0

    I am playing with the JdbcTemplate and have the following code: JdbcTemplate jdbc = new JdbcTemplate(); String[] s = (String[]) jdbc.queryForObject(SELECT_SQL, new Object[]{new Long(id)}, java.lang.String[].class); As I do not pass in a datasource to JdbcTemplate and does not call setDataSource on it I get the following NPE. Maybe a check in the code and to throw a propper exception stating somekind of error text that a datasource is not set on the template would be nice instead of a NPE. Just to add to Jurgens/Thomas list of silly TODO's instead of cool new features. java.lang.NullPointerException at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:173) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:152) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:128) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:319) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:374) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:410) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:469) at com.bmd.selfservice.dao.KundeHibernateDAO.loadKundeEmail(KundeHibernateDAO.java:55) at com.bmd.selfservice.KundeBusiness.getKundeEmail(KundeBusiness.java:40) at com.bmd.selfservice.demo.KundeDemo.email(KundeDemo.java:55) at com.bmd.selfservice.demo.KundeDemo.main(KundeDemo.java:62)

    Spring JIRA | 1 decade ago | Claus Ibsen
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection()
    2. Spring Framework
      JdbcTemplate.queryForObject
      1. org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:173)
      2. org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:152)
      3. org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:128)
      4. org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:319)
      5. org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:374)
      6. org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:410)
      7. org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:469)
      7 frames
    3. com.bmd.selfservice
      KundeDemo.main
      1. com.bmd.selfservice.dao.KundeHibernateDAO.loadKundeEmail(KundeHibernateDAO.java:55)
      2. com.bmd.selfservice.KundeBusiness.getKundeEmail(KundeBusiness.java:40)
      3. com.bmd.selfservice.demo.KundeDemo.email(KundeDemo.java:55)
      4. com.bmd.selfservice.demo.KundeDemo.main(KundeDemo.java:62)
      4 frames