Skip to content

Commit 3bbca40

Browse files
authored
Merge pull request #67 from javaevolved/copilot/add-new-slug-jdbc-vs-jooq
Add enterprise pattern: JDBC versus jOOQ
2 parents 052349a + bd6e7ba commit 3bbca40

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"id": 112,
3+
"slug": "jdbc-vs-jooq",
4+
"title": "JDBC versus jOOQ",
5+
"category": "enterprise",
6+
"difficulty": "intermediate",
7+
"jdkVersion": "11",
8+
"oldLabel": "Raw JDBC",
9+
"modernLabel": "jOOQ",
10+
"oldApproach": "Raw JDBC",
11+
"modernApproach": "jOOQ SQL DSL",
12+
"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}",
13+
"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);",
14+
"summary": "Replace raw JDBC string-based SQL with jOOQ's type-safe, fluent SQL DSL.",
15+
"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.",
16+
"whyModernWins": [
17+
{
18+
"icon": "🔒",
19+
"title": "Type-safe columns",
20+
"desc": "Column names are generated Java constants — typos and type mismatches become compiler errors instead of runtime failures."
21+
},
22+
{
23+
"icon": "📖",
24+
"title": "SQL fluency",
25+
"desc": "The jOOQ DSL mirrors SQL syntax closely, so complex JOINs, subqueries, and CTEs stay readable."
26+
},
27+
{
28+
"icon": "🛡️",
29+
"title": "Injection-free by design",
30+
"desc": "Parameters are always bound safely — no string concatenation means no SQL injection risk."
31+
}
32+
],
33+
"support": {
34+
"state": "available",
35+
"description": "jOOQ open-source edition supports all major open-source databases; older commercial databases require a paid license"
36+
},
37+
"prev": "enterprise/spring-xml-config-vs-annotations",
38+
"next": null,
39+
"related": [
40+
"enterprise/jdbc-vs-jpa",
41+
"enterprise/jdbc-resultset-vs-jpa-criteria",
42+
"enterprise/manual-transaction-vs-declarative"
43+
],
44+
"docs": [
45+
{
46+
"title": "jOOQ — Getting Started",
47+
"href": "https://www.jooq.org/doc/latest/manual/getting-started/"
48+
},
49+
{
50+
"title": "jOOQ — DSL API Reference",
51+
"href": "https://www.jooq.org/javadoc/latest/"
52+
}
53+
]
54+
}

content/enterprise/spring-xml-config-vs-annotations.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"description": "Widely available since Spring Boot 1.0 (April 2014); Spring Boot 3 requires Java 17+"
3636
},
3737
"prev": "enterprise/jdbc-resultset-vs-jpa-criteria",
38-
"next": null,
38+
"next": "enterprise/jdbc-vs-jooq",
3939
"related": [
4040
"enterprise/ejb-vs-cdi",
4141
"enterprise/jndi-lookup-vs-cdi-injection",

0 commit comments

Comments
 (0)