Skip to content
Ameen Abozaid
Planned lessonMID-022-L02

jOOQ in practice

  • Lesson 2 of 5
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

write type-safe SQL with generated classes.

Planned topics

  • jOOQ generates Java classes from the database schema (tables, columns, types) through a code generator in the build.
  • You write SQL as Java methods; the compiler catches renamed columns and wrong types.
  • It supports modern SQL (CTEs, window functions, ON CONFLICT) and maps results to records or DTOs.
  • Integrates with Spring transactions through DSLContext using the same DataSource.
  • Generate from a migrated database (Flyway plus Testcontainers) so the code and schema agree; verify licensing for your database edition before recording (open-source edition supports PostgreSQL).
Draft outline details

Demonstration

java
var rows = dsl.select(PRODUCT.CATEGORY_ID, DSL.sum(ORDER_ITEM.PRICE_CENTS))
              .from(ORDER_ITEM).join(PRODUCT).on(PRODUCT.ID.eq(ORDER_ITEM.PRODUCT_ID))
              .groupBy(PRODUCT.CATEGORY_ID)
              .fetch();

Check your understanding

What does the compiler catch that a SQL string would not?

Show answer

A renamed column or a type mismatch.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.