aspose file tools*
The moose likes JDBC and the fly likes Resultset concept Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Resultset concept" Watch "Resultset concept" New topic
Author

Resultset concept

Pankaj Tiwari
Ranch Hand

Joined: Sep 11, 2005
Posts: 55
Hi All
There is a question in my mind. Consider the following code sample

in this case does resultset fetches all the rows of table in one shot or does it maintains some kind of buffer where is stores some set of records or does it goes everytime to the database and fetch the record when i do . If the resultset fetches all the records in one shot then why java people have not provided method to get the number of records in table directly. If it maintains buffer then on what factors does the buffer size depends and can we change that size. Basically i wanted to know how internally resultset works

Thanks in advance
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by Pankaj Tiwari:


in this case does resultset fetches all the rows of table in one shot or does it maintains some kind of buffer where is stores some set of records or does it goes everytime to the database and fetch the record when i do



According to JavaDoc executeQuery methods return ResultSet Object that contains the data produced by the given query.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Malith Yapa
Ranch Hand

Joined: Jan 17, 2007
Posts: 45
Dude.. Your curiosity surprises me.. However the thing is.. If the result set uses some kind of buffer I don't see the point of it I mean it's most unlikely that it does so. although you can't get the length of it you can recall an object at a specific index.. I'm really not sure about how the api works but if you explain what you were planning to do or your intention. Perhaps I could have helped more. You better also be aware that a result set is an interface.. So if you intended to change any property like a buffer length(if it existed) you can simply define your own object(although it's not simple) implementing the result set
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Pankaj --

As has already been pointed out, ResultSet is an interface. It's up to the individual JDBC driver vendors to implement that interface (despite what Malith Yapa says, you'd never implement your own ResultSet.) Some drivers may communicate all the data from a query immediately from the database to your JVM; other, more sophisticated ones won't, but rather they will buffer the data as you suspect, sending perhaps a dozen records at a time. It depends on the architecture of the driver and on the capabilities of the specific database. But in general, a decent driver won't download all the data from a large query result immediately -- that would often be too memory intensive and involve too much communications overhead.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resultset concept