Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Closing Objects when Not In Use

When you work with objects of Microsoft SQL Server JDBC Driver, particularly the SQLServerResultSet or one of the Statement objects such as SQLServerStatement, SQLServerPreparedStatement or SQLServerCallableStatement, you should explicitly close them by using their close methods when they are no longer needed. This improves performance by freeing up driver and server resources as soon as possible, instead of waiting for the Java Virtual Machine garbage collector to do it for you.

Closing objects is particularly crucial to maintaining good concurrency on the server when you are using scroll locks. Scroll locks in the last accessed fetch buffer are held until the result set is closed. Similarly, statement prepared handles are held until the statement is closed. If you are reusing a connection for multiple statements, closing the statements before you let them go out of scope will allow the server to clean up the prepared handles earlier.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.