Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:23:18+00:00 2026-06-01T04:23:18+00:00

According to the documentation for getResultSet in java.sql.Statement , it says: Retrieves the current

  • 0

According to the documentation for getResultSet in java.sql.Statement, it says:

Retrieves the current result as a ResultSet object. This method should
be called only once per result.

Using some test code, I ran executeQuery() and several calls to getResultSet() and observed that the ResultSet returned pointed to the same object. So I’m guessing it is not returning a different ResultSet which you would need to close individually. But of course this could be unique to my JDBC drivers.

Looking at the documentation for ResultSet it says:

A default ResultSet object is not updatable and has a cursor that
moves forward only. Thus, you can iterate through it only once and
only from the first row to the last row.

This seems like a good reason why it may not be a good idea to call it multiple times as it may lead to some “gotcha” situation. If this was the sole reason, I felt that they could have just said that so I think there might be more to it than just this.

So does anyone know why one shouldn’t call getResultSet more than once per result? This question is what made me curious in the first place.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:23:19+00:00Added an answer on June 1, 2026 at 4:23 am

    The ResultSet object is an interface provided by Java JDBC — they do not provide an implementation. Even though your particular database code and associated drivers implement ResultSet so that you can call it multiple times per result, if you depend on such behavior that is outside of the contract, you are certainly playing with fire.

    One possible reason that the contract was written with the this method should be called only once per result line is for efficiency reasons. Building the ResultSet will most likely make a JDBC RPC call to the database and the authors of the JDBC specification wanted to discourage multiple round trips. They may not have wanted to force implementers to protect against multiple calls per result efficiently. Again, even though your database is protecting against that behavior does not mean the next one will.

    Most ResultSet implementations also hold a connection to the database open so that when you get certain fields (such as large blobs) it can call back to the database to get the data. Having multiple connections open or (worse) using the same connection from multiple ResultSet objects would be very dangerous/confusing.

    Also, they may have been worried about two parts of your code calling getResultSet() twice and were returned a reference to the same single unsynchronized object. This would cause confusion when next() was called and overwrote the object with multiple references.

    I’m speculating of course but I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to documentation , git update-index --refresh does this: Looks at the current index
According to the documentation of java.util.Pattern , the POSIX character class \p{Graph} ( [:graph:]
According to Android documentation, using the .getTime() method in the Android location will return
According to the documentation here: https://github.com/playframework/Play20/wiki/AssetsGoogleClosureCompiler it says: Any JavaScript file present in app/assets
According to documentation Default implementation does nothing. But... I throw exception from drawRect method
INFORMIX-SQL 7.3 Perform Screens: According to documentation, in an after editadd editupdate of table
According to the documentation for NSString's method -UTF8String : The returned C string is
According to the documentation, the decimal.Round method uses a round-to-even algorithm which is not
In my current production code, and according to documentation on msdn , the way
There's setDoOutput() in URLConnection . According to documentation I should Set the DoOutput flag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.