Available in versions: Dev (3.21) | Latest (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11
ResultQuery as Iterable
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
The org.jooq.ResultQuery type extends java.lang.Iterable, and as such, inherits the JDK's Iterable.forEach() method, as well as it being a possible foreach loop source:
// External iteration, fetching records eagerly
for (var r : create.select(BOOK.TITLE).from(BOOK))
System.out.println(r.get(BOOK.TITLE));
// Internal iteration, fetching records lazily
create.select(BOOK.TITLE).from(BOOK).forEach(r -> {
System.out.println(r.get(BOOK.TITLE));
});
Note that unlike when lazy fetching using theorg.jooq.CursorAPI, the external iteration style will eager-fetch the entire intermediateorg.jooq.Resultinto memory as jOOQ has no control over the lifecycle of thejava.util.Iterator, and the JDK doesn't know anjava.lang.AutoCloseableiterator.
Feedback
Do you have any feedback about this page? We'd love to hear it!