jQuery in Action, 2nd edition*
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "the workings of ResultSet.getFetchSize()" Watch "the workings of ResultSet.getFetchSize()" New topic
Author

the workings of ResultSet.getFetchSize()

Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
Hello,
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.
Regards
Faisal
[ 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
Faisal,
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.
return resultset.next();
Otherwise, loop and cound
while(result.next){
rowCount++
}
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().
 
Don't get me started about those stupid light bulbs.
 
subject: the workings of ResultSet.getFetchSize()
 
Similar Threads
Adding code to return an ArrayList of objects
ResultSet object returning null
PreparedStatement's executeQuery() returning resultset with no rows
How to determine the number of Result set records.
Behaviour on failure of validate in form bean