• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returning # of rows from sql query

 
Bill Brasskey
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does there exist a java function I can call that will return the number of rows returned from a sql select query, so i don't have to "select count(*)"?
...i guess i'm looking for something like the " mysql_num_rows" function in PHP.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill,
No. There are two standard ways of getting this information:

1) If you don't need the data, use select count(*)
2) If you do need the data, count up the rows as you process them
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on your needs I have a class as part of the FormattedDataSet api that converts a ResultSet into an array of Objects (Object[][]). It is straightforward to use.



The javadocs link: http://fdsapi.sourceforge.net/javadocs/com/fdsapi/ResultSetConverter.html

See the links below to read more.
 
sarah Marsh
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where can I find FormattedDataSet api?

I heared for oracle 9i there's a new way for get the rowcount, what's that?
 
Loren Rosen
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic problem is that the database itself doesn't know how many rows will be returned without executing the query, or at least a good part of the query.

You can get some an *estimate* of how may rows will be returned, since the optimizer computes that as part of its work to pick the best query plan. It's just a guess, though. For comparison, sometimes google searches will say "1-10 out of about 25,000 for..." but when you get to page 5 it says "50-60 out of 1267 for ...." What happened to the other 24,000 results? They never existed -- google's initial estimate was off.

For Oracle, you can get the estimate from EXPLAIN PLAN or from some of the v$ system views. See this discussion:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1933814740032
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<<where can I find FormattedDataSet api?>>
http://www.fdsapi.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic