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

getFetchSize().... what is it for

deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
hi all,
i want to find out the number of rows in a result set before proceesing it.
i used getFetchSize() for this but this method is returning 1 always.
i want to know what is the significance of this method and is there any method in jdbc 2.0 to find out the number of rows in a resultset.
regards
deeksha
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
According to JDBC 2.0, It Returns the fetch size for this result set...I have never tried to use it.
What you can also do is issue a select count (*) before executing your querry.
Bosun

Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
sateesh arumbaka
Greenhorn

Joined: May 17, 2001
Posts: 5

Here is a solution for ur problem
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = statement.executeQuery(query);
rs.last();
int numberOfRows = rs.getRow();
rs.beforeFirst();
mail me if u have any questions
sateesh

Originally posted by deekasha gunwant:
hi all,
i want to find out the number of rows in a result set before proceesing it.
i used getFetchSize() for this but this method is returning 1 always.
i want to know what is the significance of this method and is there any method in jdbc 2.0 to find out the number of rows in a resultset.
regards
deeksha

Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

topic covered already in this(and many more previous posts) http://www.javaranch.com/ubb/Forum3/HTML/001865.html
compares the two techniques for retrieving row counts.

Jamie
[ February 01, 2006: Message edited by: Marilyn de Queiroz ]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

and what is FetchSize?
The number of rows that should be fetched from the database each time new rows are needed. This is much different than the total number of rows.
For example, if your query finds 10,000 matches, it won't return all 10,000 rows from the database. This is where fetch size comes in to play. If fetchSize is 10, then it will initially retrieve the first ten rows. When you call rs.next() after row ten, the program makes a call to the database to return the next 10(or whatever the fetchSize is) rows.
Jamie
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: getFetchSize().... what is it for