7.6.5. Stored Procedures with jOOQ

A great benefit of jOOQ is its support for working with stored procedures. Stored procedures are extracted to the *.Routines.* package. From there, you can work with them easily. For instance, the following code in Java:

  1. int invoiceId = dsl.nextval(GEN_INVOICE_ID).intValue();
  2. spAddInvoice(dsl.configuration(),
  3. invoiceId,
  4. customerId,
  5. invoiceDate);

is equivalent to getting the next value of the generator using the following SQL query:

  1. SELECT NEXT VALUE FOR GEN_INVOICE_ID
  2. FROM RDB$DATABASE

and calling the stored procedure after that:

  1. EXECUTE PROCEDURE SP_ADD_INVOICE (
  2. :INVOICE_ID, :CUSTOMER_ID, :INVOICE_DATE );

jOOQ also provides tools to build simple DDL queries, but we do not cover them here.