JOOQ - difference between fetchAny and fetchOne

Is there a (real) difference between fetchAny() and fetchOne() ? Both return the exact same record. The API documentation is the same, but the implementation (on github) is different.

+10
java sql jooq
source share
2 answers

The goal of the two methods is different:

Essentially, when you use fetchOne() request should return 0 or 1 record. When you use fetchAny() query can return any number of records, and if the database returns any record, the first one retrieved from the JDBC result set will be returned.

Note that fetchOne() is thus trying to fetch 2 entries from the JDBC driver (decide whether TooManyRowsException needs to be thrown), while fetchAny() only gets at most 1 record.

+14
source share

javadoc explains the difference. fetchAny() returns the first record, while fetchOne() expects the request to return zero or one record, and throws an exception if the request returned more than one record.

+2
source share

All Articles