English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

that have been created with that Statement? If I close a Connection, does it close all Statements, PreparedStatements and CallableStatements and ResultSets that have been created using these Statements? Do I have to close each one explicitly or if I close the topmost hierarchy it closes all subordinate / tree level ?

2006-09-08 06:13:25 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

Well I dont care about "good code" nor did I ask about cding practices. But thanks for the answer. What I wanted to know was, if I close the connection itself, then everything that has been created from the connection in the first place, should also be closed automatically right? That means memory should be released and garbage collected, database resources must be closed, etc.

2006-09-08 09:45:11 · update #1

4 answers

In many cases, it is desirable to immediately release ResultSet and Statement's database and JDBC resources instead of waiting for this to happen when it is automatically closed.
So, for a good code, you must close all ResultSet, Statement first, and then the Connection. Connection opens a connection to a DB, and Statements opens a query to a specific table and finally, ResultSet creates a cursor on such table.

Creating:
1.Connection
2.Statement or PreparedStatement or CallableStatement
3.ResultSet

Closing:
4.ResultSet
5.Statement or PreparedStatement or CallableStatement
6.Connection

2006-09-08 07:59:50 · answer #1 · answered by sonfarX 4 · 0 0

While most JDBC drivers will close and release all related resources when you close the connection, there is no guarantee. A poorly written driver may not properly release associated resources. Those resources will eventually be released as garbage collection takes place, but there could be a significant delay.

Also, if the connections are pooled, then calling close() does NOT close the connection, but instead returns it to the pool.

Therefore, you should ALWAYS explicitly close all database resources as you finish with them.

2006-09-11 03:29:15 · answer #2 · answered by vincentgl 5 · 0 0

see..if you close a statement then all the resultset will not be useful..it will give you error...
so it doesnt mean that all are closed..

and if you close connection then they are not going to be garbage collected properly...(Sorry 4 English speaking problem)

2006-09-08 13:18:47 · answer #3 · answered by patel.nachiket 2 · 0 0

Only if there directly linked to it!

2006-09-08 13:18:40 · answer #4 · answered by myspace.com/random129 1 · 0 0

fedest.com, questions and answers