aspose file tools*
The moose likes JDBC and the fly likes query regarding getFetchSize Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "query regarding getFetchSize" Watch "query regarding getFetchSize" New topic
Author

query regarding getFetchSize

anagha patankar
Ranch Hand

Joined: Dec 26, 2005
Posts: 53
On ne of the websites - it is written to improve performance one should set the "fetchSize" of the prepared statement and ResultSet.

1 >Lets say if I set a fetch size of 10 and my query returns 20 records - are all records held in memory or only 10 are in memory and when I iterate to the 11th record - then the remaining are fetched from database ?

Regards,
-anagha
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29261
    
140

Anagha,
That would result in two trips to the database. Sometimes tuning the fetch size is advisable as it results in less network trips.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29261
    
140

Forgot to mention: I would advise against making the fetch size smaller than the default.
anagha patankar
Ranch Hand

Joined: Dec 26, 2005
Posts: 53
Thanks Jeanne for your replies .

So when you say there will be two trips to the database :
1 >Where is the resultset stored - is that stored in SGA ( In case of Oracle )
2 >If we are using a resultset - then believe all the data is anyway on the server side ( not like disconnected rowset )

So are you saying that after query execution ( results obtained = 20 rows & fetchSize = 10 ) that 20 rows will be stored in SGA

So where are the first 10 records read / picked from

What happens when we access the 11th record ?

Too many questions and too much confusion at my end .

Any answers will be greatly appreciated .

Regards,
-anagha
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29261
    
140

I don't know about what is stored in SGA. That is within Oracle, so I don't need to think about it as an app developer.

> If we are using a resultset - then believe all the data is anyway on the
> server side ( not like disconnected rowset )
It's on the client side too. When you call rs.next(), the data is transfered to the client side. We wouldn't want this to happen on every call to rs.next() so fetch size tells the driver how often to go to the server to get more data.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: query regarding getFetchSize
 
Similar Threads
Fetch only 'n' records from the ResultSet
Java Interview Questions
Pagination
Limiting ResultSet
regarding MS access sql query