aspose file tools*
The moose likes JDBC and the fly likes NullPointerException while closing PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "NullPointerException while closing PreparedStatement" Watch "NullPointerException while closing PreparedStatement" New topic
Author

NullPointerException while closing PreparedStatement

Jay Mehta
Greenhorn

Joined: Feb 04, 2003
Posts: 4
I get this error while I close a PreparedStatement. I have checked to see if the PreparedStatement was null before calling close on it, It is not null yet an error is thrown.My connection is also valid and this error is thrown sometimes.Can somebody help??
java.lang.NullPointerException
at oracle.jdbc.dbaccess.DBData.clearIt(DBData.jav(Compiled Code))
at oracle.jdbc.dbaccess.DBDataSetImpl.clearItem(DBDataSetImpl.java:2154)
at oracle.jdbc.driver.OraclePreparedStatement.clearParameters(OraclePreparedStatement.java:2594)
at com.ibm.ejs.cm.cache.CachedStatement.clearParameters(CachedStatement.java)
at com.ibm.ejs.cm.cache.StatementCache.releaseStatement(StatementCache.java)
at com.ibm.ejs.cm.cache.CachedStatement.close(CachedStatement.java)
at com.ibm.ejs.cm.proxy.StatementProxy.__close(StatementProxy.java(Compiled Code))
at com.ibm.ejs.cm.proxy.StatementProxy.close(StatementProxy.java(Compiled Code))
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
Are you maybe closing the connection before the statement? You might be doing this clearly in your code, or if you have a web or ejb app, maybe it is being done by the app container.


Reid - SCJP2 (April 2002)
Jay Mehta
Greenhorn

Joined: Feb 04, 2003
Posts: 4
I am very sure that i dont close my connection,Infact in my code i check if the PreparedStatement is null.I am using batching with PreparedStatements..could this be an issue?..
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
Two different concepts here. Just because your reference to a prepared statement isn't null doesn't mean that you haven't closed the statement. All testing for null tells you is if the reference is null, nothing more. What matters is if you (or the container) have called PreparedStatement.close() or Connection.close().
As to using a batch, I don't know if a reason why it would matter. I've used batches before, never ran into anything like what you describe.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException while closing PreparedStatement
 
Similar Threads
NullPointerException while closing PreparedStatements
weird Db2exception
NullPointerException while closing PreparedStatement
stale connection exception
EJB failure: CNTR0019E: Non-application exception