by throwaway4good · 6y ago · 0 comments
Just embed the SQL statement in a string.
In same way you would embed a snippet of HTML, XML or anything else.
(You can remove some of the boiler plate of a classic Java prepared statement using a library though ... nothing wrong in that.)
Instead of something like this:
Query query = create.select(field("BOOK.TITLE"), field("AUTHOR.FIRST_NAME"), field("AUTHOR.LAST_NAME"))
.from(table("BOOK"))
.join(table("AUTHOR"))
.on(field("BOOK.AUTHOR_ID").eq(field("AUTHOR.ID")))
.where(field("BOOK.PUBLISHED_IN").eq(1948));
Plus you may sit with a SQL dialect not supported by the "Fluent API".This makes sense for simple software, but jOOQ generates DB specific SQL queries depending on your DB dialect. E.g. we have a big product which supports nearly all big databases and jOOQ abstracts away the DB specific stuff wonderfully.