Search code examples
javamysqljdbcresultset

If the ResultSet fetches and stores the value in memory, why ResultSet objects cannot be used after closing it?


I am new to JDBC and i am using mysql JDBC Driver and i have not understood how the resultset works.

The JDBC API Implementation notes say

By default, ResultSets are completely retrieved and stored in memory. In most cases this is the most efficient way to operate and, due to the design of the MySQL network protocol, is easier to implement.

If the resultset object fetches the data and stores in memory, then why the object is not accessed after closing it as it is still in the memory?

Will calling the close() method cuts the reference to the data? If so how it is done?

Help me with it.


Solution

  • If the resultset object fetches the data and stores in memory, then why the object is not accessed after closing it as it is still in the memory?

    Because that is what the JDBC API specification says should happen:

    " void close() throws SQLException

    Releases this ResultSet object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed."


    Will calling the close() method cuts the reference to the data?

    Effectively yes.


    If so how it is done?

    Having had a brief look at it, it is complicated. Read the source code if you really want to know. It is on GitHub:


    .... i have not understood how the resultset works.

    You don't need to understand that to use JDBC. You just need to understand how you are supposed to use ResultSet ... and related classes. The JDBC javadocs explain that.