Reputation: 3727
JDBC API has provided a rich set of functions for the programmers to carry on the database operations. I am surprised what restricted them to provide a function such as getCount() that will return the number of rows obtained by executing a query.
Upvotes: 1
Views: 323
Reputation: 11185
What you get back when you execute a query is a result set that iterates over the rows. A database need not necessarily return information on how many rows a query fetches, since it may decide to optimize the fetch and only return say the first X rows.
You can always get the count of the rows in the same transaction and obtain the information you want. Another option is to use a scrollable resultset and traverse to the last row and then get the row count.
[EDIT]
An FAQ from the Oracle tech network recommends what I just wrote in my answer, albeit they do not provide the internal technical reason behind it.
Upvotes: 3