General J2EE: Resultset.close() Query
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.
- 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
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
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,
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 -
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.
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
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.
Sorry, I repeated myself at the end of the previous post. Was organizing the post and forgot to remove the text at the end
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.