Available in versions: Dev (3.16) | Latest (3.15) | 3.14 | 3.13 | 3.12 | 3.11 | 3.10 | 3.9 | 3.8 | 3.7

JDBC Connection

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

Sometimes, access to the JDBC java.sql.Connection is required from code that would otherwise use jOOQ. Your DSLContext and Configuration is configured with a JDBC Connection or DataSource via a org.jooq.ConnectionProvider, but rather than going through those SPIs, you can access (and acquire) a JDBC Connection directly from your DSLContext. Just write:

// Alternatively, use DSLContext.connectionResult() to return a result from the lambda.
create.connection((Connection c) -> {

    // Modify your JDBC connection or get information from it
    c.setClientInfo("key", "value");
    
    // Operate on this modified JDBC connection
    DSL.using(c)
       .select(BOOK.TITLE)
       .from(BOOK)
       .fetch();
});

Feedback

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

The jOOQ Logo