I want to shut statement automatically
I want to close statement automatically.
I want to achieve it by the technology of the following conditions.
- java1.5
- spring framework2.5
It seems not to close automatically in the setting of default though I think that transaction manager of spring automatically shuts statement.
I do not want to call close()
of statement as much as possible in the method for maintainability.
Is there 开发者_运维问答a method of statement's closing?
Moreover, is there an official site or document that shows the reason when there is no closing method?
The amount of coding increases if coming for all the methods to have to call close() of statement, and there is a problem that the possibility that the omission is generated goes out.
Moreover, I am making the framework. It wants to make the restriction as much as possible by such a reason and to make a little method.
If I understood your question right you can use the http://commons.apache.org/dbcp/ to do the closing for you, as far as I know this is the standard anyway so most likely you are already using it, as long as you use spring or jndi to provide your database connectivity. In your configuration for the database connection configure removeAbandoned=true and removeAbandonedTimeout=50 See http://commons.apache.org/dbcp/configuration.html (the lowest block) for details. Be aware that you should a rather large connection pool if you rely on it to clean up your connections.
To the question on why there is no closing method: there is.
- For Connections: http://download.oracle.com/javase/6/docs/api/java/sql/Connection.html#close()
- For Statements: http://download.oracle.com/javase/6/docs/api/java/sql/Statement.html#close()
- For ResultSets: http://download.oracle.com/javase/6/docs/api/java/sql/ResultSet.html#close()
closing a Connection will close all its Statements. closing a Statement will close all its ResultSets.
After all, its no good style to do so. I recommend calling the close() by yourself and use the abandonment removal only to find the places where you forgot to do so by adding logAbandoned=true
精彩评论