Discussions

General J2EE: Resultset.close() Query

  1. Resultset.close() Query (5 messages)

    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

    Threaded Messages (5)

  2. Result Close[ Go to top ]

    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
  3. Resultset.close() Query[ Go to top ]

    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.
  4. 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.
  5. Sorry, I repeated myself at the end of the previous post. Was organizing the post and forgot to remove the text at the end
  6. 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.