I have a query. I have opened a connection, Statement and then a resultSet. When i have finished with that I have closed Statement and Connection.
If i have not closed the result set Will it remain as unclosed connection.
Could somebody clear my doubt.
Thanks
-
Resultset.close() Query (5 messages)
- Posted by: Shahul Hameed
- Posted on: April 28 2005 00:45 EDT
Threaded Messages (5)
- Result Close by vinay vinay on April 28 2005 06:44 EDT
- Resultset.close() Query by Sergei Batiuk on April 28 2005 07:41 EDT
- Resultset.close() Query by Kingshuk Bandyopadhyay on April 28 2005 07:55 EDT
- Resultset.close() Query by Kingshuk Bandyopadhyay on April 28 2005 07:58 EDT
- Resultset.close() Query by Shahul Hameed on April 29 2005 12:49 EDT
- Resultset.close() Query by Kingshuk Bandyopadhyay on April 28 2005 07:58 EDT
-
Result Close[ Go to top ]
- Posted by: vinay vinay
- Posted on: April 28 2005 06:44 EDT
- in response to Shahul Hameed
Whenever u create the Result Object then it will goes to the databse and pointing to the first row in a table. whenever u r retriving the columns from Result set that result set wil use the Connection object. if u make it result set object is active and statement and connection is null then it wil give whenever u retriving the values Exception -
Resultset.close() Query[ Go to top ]
- Posted by: Sergei Batiuk
- Posted on: April 28 2005 07:41 EDT
- in response to Shahul Hameed
Shahul,
The JavaDoc for the Connection.close() method starts with "Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released."
Therefore, if you close() the connection, all the achquired objects, such as Statements and ResultSets will be closed.
However, if you use connection pool, the close() method returns the connection to the pool and doesn't actually close the connection. In this case dependant objects may be left open. In this case, I think, it is better to close them manually.
Hope this helps,
Sergei. -
Resultset.close() Query[ Go to top ]
- Posted by: Kingshuk Bandyopadhyay
- Posted on: April 28 2005 07:55 EDT
- in response to Shahul Hameed
I have a query. I have opened a connection, Statement and then a resultSet. When i have finished with that I have closed Statement and Connection.If i have not closed the result set Will it remain as unclosed connection.Could somebody clear my doubt.Thanks
From the api documentation of result set -
<quote>
A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.
</quote>
So if you are using java.sql.Statement and if you call close on it the result set will get closed.
the situation is different if -
1. you are using PreparedStatement/CallableStatement
AND
2. You are caching connections and these statements
For example weblogic allows you to do that.
In this case, closing a connection and statements merely returns it back to the pool. So your resultset will stay alive until some else uses the same cached statement (prepared or callable)
If you are NOT pooling your connections and statements then a close on the statement
If you are pooling your connections and statements then the result set will NOT be closed when you "close" your connections and statements. WebLogic for example lets you pool statements. So when you close a statement it becomes available in the pool again - to be used by someone else. -
Resultset.close() Query[ Go to top ]
- Posted by: Kingshuk Bandyopadhyay
- Posted on: April 28 2005 07:58 EDT
- in response to Kingshuk Bandyopadhyay
Sorry, I repeated myself at the end of the previous post. Was organizing the post and forgot to remove the text at the end -
Resultset.close() Query[ Go to top ]
- Posted by: Shahul Hameed
- Posted on: April 29 2005 00:49 EDT
- in response to Kingshuk Bandyopadhyay
Thanks for the answers.
I am using Weblogic connection pooling so i feel the connection is pooled rather than closed and it used by other resources. So I did close them all manually. That's helps me.