Two Laptop Bag
The moose likes JDBC and the fly likes Statement Closure in a loop: performance and memory management Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Statement Closure in a loop: performance and memory management" Watch "Statement Closure in a loop: performance and memory management" New topic
Author

Statement Closure in a loop: performance and memory management

Jigar M Gohil
Greenhorn

Joined: Dec 14, 2011
Posts: 9
Hi All,
This is more related to performance and memory management. I have following scenario:



Here, After processing the resultset for one select query, the selectStatement reference is being assigned to new select statement and further resultset reference gets a new Resultset Object.
What happens to previous Statement & Resultset Objects?
What I understand is they become candidate for GC.
But my question is shall I close them before they get assigned new object references? From performance/memory management point of view, does it make any difference?

Thanks & Regards,
Jigar.

Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1098

I would close them, as they are using up database resources whilst open.
also it is best to put the closes in a finally block so it happens even if you have an exception.
myyron latorilla
Greenhorn

Joined: Dec 10, 2009
Posts: 26
You need to close the statement object that's why it has a close method and relying to GC is not enough. At some point you will encounter an exception if you do not close the statement object. ResultSet implicitly closed when you close the statement.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Statement Closure in a loop: performance and memory management
 
Similar Threads
To Nikhil Pendharkar for IBM 287
best programming practises of JDBC
GC question..........
nested ResultSets
Bug in JDBC ? Simple Select statement not returning a resultSet