Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getFetchSize().... what is it for

 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sateesh arumbaka
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic