File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes the workings of ResultSet.getFetchSize() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "the workings of ResultSet.getFetchSize()" Watch "the workings of ResultSet.getFetchSize()" New topic

the workings of ResultSet.getFetchSize()

Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
I have a method which looks something like this:

The validate method does the following to return an int:

(broken up the lines for display)
In the UserBean, there is a method isUserValid() and that checks whether validate returns greater than 0.
Unfortunately, whether the user is valid or not, the result is always 0. I have another method called queryResultsAL() which returns an ArrayList of results, if I subsitute the above code with following:

Then this works (unfortunately also returns greater than 0 when no username and password are specified but there will be validations to ensure empty strings never reach that code).
I am somewhat confused about the workings of getFetchSize() which I thought will return how many results are retrieved by the query.
Can any one help me to understand this and correct my understanding.
[ February 10, 2004: Message edited by: Faisal Khan ]

The secret to creativity is knowing how to hide your sources.
Peyton McCullough
Ranch Hand

Joined: Feb 07, 2004
Posts: 31
I'm not exactly sure what getFetchSize() does. Though I do know of another method to count the number of results:

Maybe that will aid you.
Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
GetFetchSize() returns the number of records that database fetch to your applicaton at a time. By default, the fetch size is 10. Let's assume that your query result contains 100 records. It would takes 10 round trips to transfer 100 records to your application (10 x 10 = 100). GetFetchSize() does not return the number of records in the resultset. If you need to ensure that there is at least one record.
Otherwise, loop and cound
You would be in better shape when using PreparedStatement since much overhead is reduced.
Hope it help
Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
Thanks guys for the feedback and clarification of getFetchSize().
subject: the workings of ResultSet.getFetchSize()
jQuery in Action, 3rd edition