Available in versions: Dev (3.22) | Latest (3.21) | 3.20 | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

Throw exceptions

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

Some databases, such as SQL Server or Sybase, can raise several errors from a single statement or batch, for example when executing procedural logic that interleaves result sets, update counts, and errors. JDBC exposes these errors through Statement.getMoreResults() and chained java.sql.SQLException instances. The throwExceptions setting governs how jOOQ propagates them. The possible values of org.jooq.conf.ThrowExceptions are:

With THROW_NONE, each exception is available from its org.jooq.ResultOrRows element:

Results results = DSL.using(connection, dialect, new Settings().withThrowExceptions(THROW_NONE))
    .fetchMany("...");

for (ResultOrRows r : results.resultsOrRows()) {
    if (r.exception() != null)
        System.out.println("Exception: " + r.exception().getMessage());
    else if (r.result() != null)
        System.out.println("Result:\n" + r.result());
    else
        System.out.println("Update count: " + r.rows());
}

Example configuration

Settings settings = new Settings()
    .withThrowExceptions(ThrowExceptions.THROW_FIRST); // Defaults to THROW_ALL

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo