Thursday, May 19, 2011

Closing a ResultSet and PreparedStatement In JBoss

Share it Please

It is very important to close the Resultset and PreparedStatements that are opened while working with Database. These needs to be closed if we want to use PreparedStatementCache in our application Server.
JBoss application servers provides us options in closing the ResultSet and PreparedStatement if we miss to close them. We need to add
To the Datasource-ds.xml files. This allows the application Server to close any ResultSet and PreparedStatement by itself if we miss them. Once enabling this feature, the console shows various exceptions if it finds any Unclosed ResultSet and PreparedStatement.
01:21:26,466 WARN  [WrappedConnection] Closing a statement you left open, please do your own housekeeping java.lang.Throwable: STACKTRACE         at org.jboss.resource.adapter.jdbc.WrappedConnection.registerStatement( at org.jboss.resource.adapter.jdbc.WrappedStatement.<init>( at  org.jboss.resource.adapter.jdbc.jdk6.WrappedStatementJDK6.<init>(         at org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6.wrapStatement(         at org.jboss.resource.adapter.jdbc.WrappedConnection.createStatement( at SamplePoolTestServlet.doPost(

The application server closes a Statement which is opened at SamplePoolTestServlet:42 and

01:21:26,466 WARN  [WrappedConnection] Closing a result set you left open! Please close it STACKTRACE         at org.jboss.resource.adapter.jdbc.WrappedStatement.registerResultSet(         at org.jboss.resource.adapter.jdbc.WrappedStatement.executeQuery(  at SamplePoolTestServlet.doPost(
Closes ResultSet which is opened at SamplePoolTestServlet:43

This feature can be very useful in development which finds unclosed ResultSets and PreparedStatements, But they would be costly when used in production.

More Articles to Come . Happy Coding ...

No comments :

Post a Comment