0

How can I find out if the next call to ResultSet.next() will fetch more rows from the database?

I could set the fetch size (e.g. ResultSet.setFetchSize(1000)) and then check if ResultSet.getRow() is a multiple of the fetch size (e.g. 1000).

This is cumbersome if the code is trying to auto-tune the fetch size to maximize row processing speed. In other words, the fetch size may not be constant.

Note: I am using an Oracle database. However, a solution for any database would be nice but not required.

Nathan
  • 6,095
  • 6
  • 42
  • 63
  • Why do you need to know this? If you are iterating over a loop using `ResultSet#next`, then what is the problem with just letting the loop stop when no more records are available? – Tim Biegeleisen May 25 '20 at 16:44
  • Let's say I am fetching a billion rows. I can greatly improve the throughput if I set the fetch size to an optimal number. I do not want to hand tune the fetch size for every query. I would like the code to automatically tune the fetch size. – Nathan May 25 '20 at 16:50
  • Then I suggest limiting the size of the result set in the query itself, [see here](https://stackoverflow.com/questions/470542/how-do-i-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering). – Tim Biegeleisen May 25 '20 at 16:51
  • Limiting the size of the result set is not going to help auto-tune the fetch size. Besides, I want to process all the rows in the table (i.e. billions of rows). – Nathan May 25 '20 at 17:07

0 Answers0