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
<track-statements>true</track-statements>
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(WrappedConnection.java:894) at org.jboss.resource.adapter.jdbc.WrappedStatement.<init>(WrappedStatement.java:59) at org.jboss.resource.adapter.jdbc.jdk6.WrappedStatementJDK6.<init>(WrappedStatementJDK6.java:41) at org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6.wrapStatement(WrappedConnectionJDK6.java:65) at org.jboss.resource.adapter.jdbc.WrappedConnection.createStatement(WrappedConnection.java:176) at SamplePoolTestServlet.doPost(SamplePoolTestServlet.java:42)
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 yourself.java.lang.Throwable: STACKTRACE at org.jboss.resource.adapter.jdbc.WrappedStatement.registerResultSet(WrappedStatement.java:909) at org.jboss.resource.adapter.jdbc.WrappedStatement.executeQuery(WrappedStatement.java:227) at SamplePoolTestServlet.doPost(SamplePoolTestServlet.java:43)
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