Replace raw JDBC string-based SQL with jOOQ's type-safe, fluent SQL DSL.
String sql = "SELECT id, name, email FROM users "
+ "WHERE department = ? AND salary > ?";
try (Connection con = ds.getConnection();
PreparedStatement ps =
con.prepareStatement(sql)) {
ps.setString(1, department);
ps.setBigDecimal(2, minSalary);
ResultSet rs = ps.executeQuery();
List<User> result = new ArrayList<>();
while (rs.next()) {
result.add(new User(
rs.getLong("id"),
rs.getString("name"),
rs.getString("email")));
}
return result;
}
DSLContext dsl = DSL.using(ds, SQLDialect.POSTGRES);
return dsl
.select(USERS.ID, USERS.NAME, USERS.EMAIL)
.from(USERS)
.where(USERS.DEPARTMENT.eq(department)
.and(USERS.SALARY.gt(minSalary)))
.fetchInto(User.class);
Type-safe columns
Column names are generated Java constants — typos and type mismatches become compiler errors instead of runtime failures.
SQL fluency
The jOOQ DSL mirrors SQL syntax closely, so complex JOINs, subqueries, and CTEs stay readable.
Injection-free by design
Parameters are always bound safely — no string concatenation means no SQL injection risk.
jOOQ open-source edition supports all major open-source databases; older commercial databases require a paid license
jOOQ (Java Object Oriented Querying) generates Java code from your database schema, turning table and column names into type-safe Java constants. The fluent DSL mirrors SQL syntax so queries are readable and composable. All parameters are bound automatically, eliminating SQL injection risk. Unlike JPA/JPQL, jOOQ embraces SQL fully — window functions, CTEs, RETURNING clauses, and vendor-specific extensions are all first-class.