Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions content/enterprise/jdbc-vs-jooq.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"id": 112,
"slug": "jdbc-vs-jooq",
"title": "JDBC versus jOOQ",
"category": "enterprise",
"difficulty": "intermediate",
"jdkVersion": "11",
"oldLabel": "Raw JDBC",
"modernLabel": "jOOQ",
"oldApproach": "Raw JDBC",
"modernApproach": "jOOQ SQL DSL",
"oldCode": "String sql = \"SELECT id, name, email FROM users \"\n + \"WHERE department = ? AND salary > ?\";\ntry (Connection con = ds.getConnection();\n PreparedStatement ps =\n con.prepareStatement(sql)) {\n ps.setString(1, department);\n ps.setBigDecimal(2, minSalary);\n ResultSet rs = ps.executeQuery();\n List<User> result = new ArrayList<>();\n while (rs.next()) {\n result.add(new User(\n rs.getLong(\"id\"),\n rs.getString(\"name\"),\n rs.getString(\"email\")));\n }\n return result;\n}",
"modernCode": "DSLContext dsl = DSL.using(ds, SQLDialect.POSTGRES);\n\nreturn dsl\n .select(USERS.ID, USERS.NAME, USERS.EMAIL)\n .from(USERS)\n .where(USERS.DEPARTMENT.eq(department)\n .and(USERS.SALARY.gt(minSalary)))\n .fetchInto(User.class);",
"summary": "Replace raw JDBC string-based SQL with jOOQ's type-safe, fluent SQL DSL.",
"explanation": "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.",
"whyModernWins": [
{
"icon": "🔒",
"title": "Type-safe columns",
"desc": "Column names are generated Java constants — typos and type mismatches become compiler errors instead of runtime failures."
},
{
"icon": "📖",
"title": "SQL fluency",
"desc": "The jOOQ DSL mirrors SQL syntax closely, so complex JOINs, subqueries, and CTEs stay readable."
},
{
"icon": "🛡️",
"title": "Injection-free by design",
"desc": "Parameters are always bound safely — no string concatenation means no SQL injection risk."
}
],
"support": {
"state": "available",
"description": "jOOQ open-source edition supports all major open-source databases; older commercial databases require a paid license"
},
"prev": "enterprise/spring-xml-config-vs-annotations",
"next": null,
"related": [
"enterprise/jdbc-vs-jpa",
"enterprise/jdbc-resultset-vs-jpa-criteria",
"enterprise/manual-transaction-vs-declarative"
],
"docs": [
{
"title": "jOOQ — Getting Started",
"href": "https://www.jooq.org/doc/latest/manual/getting-started/"
},
{
"title": "jOOQ — DSL API Reference",
"href": "https://www.jooq.org/javadoc/latest/"
}
]
}
2 changes: 1 addition & 1 deletion content/enterprise/spring-xml-config-vs-annotations.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"description": "Widely available since Spring Boot 1.0 (April 2014); Spring Boot 3 requires Java 17+"
},
"prev": "enterprise/jdbc-resultset-vs-jpa-criteria",
"next": null,
"next": "enterprise/jdbc-vs-jooq",
"related": [
"enterprise/ejb-vs-cdi",
"enterprise/jndi-lookup-vs-cdi-injection",
Expand Down