What is causing Spring 1.2 NullPointerException when creating a prepared statement?
Using Spring 1.2.1 and oracle.jdbc.pool.OracleDataSource 10.2.0.3.0 Sometimes I get a stack trace like below. I think this is caused by the connection pool filling up. Does anyone know the reason for sure? Also is it better to use newer versions of Spring or Oracle JDBC?
java.lang.NullPointerException at org.springframework.jdbc.core.PreparedStatementCreatorFactory $ PreparedStatementCreatorImpl.createPreparedStatement (PreparedStatementCreatorFactory.java:213) at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:444) at org.springframework.jdbc.core.JdbcTemplate.query (JdbcTemplate.java:491) at org.springframework.jdbc.core.JdbcTemplate.query (JdbcTemplate.java:522) at org.springframework.jdbc.core.JdbcTemplate.query (JdbcTemplate.java:543) at org.springframework.jdbc.object.SqlQuery.execute (SqlQuery.java:114) at org.springframework.jdbc.object.SqlQuery.execute (SqlQuery.java:124) at sps.wfds.biz.glacier.MemberDAO.create (MemberDAO.java:44) at sps.wfds.biz.glacier.MemberDAO.create (MemberDAO.java:23) at sps.wfds.biz.glacier.AbstractDAO.createAndValidate (AbstractDAO.java:22) at sps.wfds.web.interceptor.AbstractPrincipal.init (AbstractPrincipal.java:87) at sps.wfds.web.interceptor.AbstractPrincipal.getAttributes (AbstractPrincipal.java:66) at sps.wfds.web.interceptor.AbstractPrincipal.getAttribute (AbstractPrincipal.java:60) at sps.wfds.web.interceptor.AbstractPrincipal.setLocale (AbstractPrincipal.java:38) at sps.wfds.web.util.LocaleUtil.setLocale (LocaleUtil.java:24) at sps.wfds.web.interceptor.SSOPrincipal. (SSOPrincipal.java:22) at sps.wfds.web.interceptor.SSOAuthority.getPrincipal (SSOAuthority.java:18) at sps.wfds.web.interceptor.Authorization.preHandle (Authorization.java:44) at org.springframework.web.servlet.DispatcherServlet.doDispatch (DispatcherServlet.java:674) at org.springframework.web.servlet.DispatcherServlet.doService (DispatcherServlet.java:625) at org.springframework.web.servlet.FrameworkServlet.serviceWrapper (FrameworkServlet.java:386) at org.springframework.web.servlet.FrameworkServlet.doGet (FrameworkServlet.java:346) at javax.servlet.http.HttpServlet.service (HttpServlet.java:689)
source to share
This has nothing to do with Spring.
DataSource.getConnection()
should never return null; it must either return a valid connection or discard SQLException
. The error was caused by an error oracle.jdbc.pool.OracleDataSource
.
Update
According to Oracke Documentation, this happens when:
- the maximum number of connections is already allocated in the pool;
- ConnectionWaitTimeout is set to non-zero
- you were waiting for getConnection () for this duration and no connections were returned to the pool.
So, with that in mind, you can:
- Review your code to make sure there is no connection leak.
- Increase pool size
- Increase connection timeout
- Use a different pool :-) or write a simple wrapper around the OracleDataSource that will check for "null" and throw a SqlException instead.
In this last scenario, you will only trade one exception for another (NPE -> SqlException). Of course it would be more appropriate, but it doesn't really solve the problem.
source to share