|The jOOQ User Manual. Multiple Pages : Getting started with jOOQ : Different use cases for jOOQ : jOOQ as a SQL builder with code generation||previous : next|
In addition to using jOOQ as a standalone SQL builder, you can also use jOOQ's code generation features in order to compile your SQL statements using a Java compiler against an actual database schema. This adds a lot of power and expressiveness to just simply constructing SQL using the query DSL and custom strings and literals, as you can be sure that all database artefacts actually exist in the database, and that their type is correct. An example is given here:
// Fetch a SQL string from a jOOQ Query in order to manually execute it with another tool. String sql = create.select(BOOK.TITLE, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME) .from(BOOK) .join(AUTHOR) .on(BOOK.AUTHOR_ID.equal(AUTHOR.ID)) .where(BOOK.PUBLISHED_IN.equal(1948)) .getSQL();
The SQL string that you can generate as such can then be executed using JDBC directly, using Spring's JdbcTemplate, using Apache DbUtils and many other tools.
If you wish to use jOOQ only as a SQL builder with code generation, the following sections of the manual will be of interest to you: