In our Java project we have started to use jooq for query building instead of plain SQL strings. The library is awesome, but I have a question (since I am jooq-newbie): Is it possible to create database using jooq, but WITHOUT PROJECT INCLUDED jooq mapping/generator?
-
Do you mean to generate code, or do you mean to create a database? (jOOQ has no formal support for DDL, but you can still use plain SQL commands to execute DDL). Do you mean you wouldn't include jooq-meta and jooq-codegen?Lukas Eder– Lukas Eder2012-11-09 11:09:51 +00:00Commented Nov 9, 2012 at 11:09
-
We want to create a database via invoking stored procedure.KernelPanic– KernelPanic2012-11-16 10:38:14 +00:00Commented Nov 16, 2012 at 10:38
-
Please be a bit more specific. It is very hard to answer this question. See the Stack Overflow FAQ for more detailsLukas Eder– Lukas Eder2012-11-16 10:48:44 +00:00Commented Nov 16, 2012 at 10:48
-
I think that author mean if he can skip jooq.org/tutorial.php#step2 this step, so he could define table/column names as a stringkskaradzinski– kskaradzinski2012-11-22 21:21:26 +00:00Commented Nov 22, 2012 at 21:21
-
@skowron-line: Maybe, although I'm still not sure how they want to "create a database" with jOOQ...Lukas Eder– Lukas Eder2012-11-23 14:26:34 +00:00Commented Nov 23, 2012 at 14:26
1 Answer
There is a lot that you can do with jOOQ without relying on its code generator. The getting started guide from the manual mentions some examples:
http://www.jooq.org/doc/2.6/manual/getting-started/use-cases/jooq-as-a-standalone-sql-builder/
For instance:
String sql = create.select(
fieldByName("BOOK","TITLE"),
fieldByName("AUTHOR","FIRST_NAME"),
fieldByName("AUTHOR","LAST_NAME"))
.from(tableByName("BOOK"))
.join(tableByName("AUTHOR"))
.on(fieldByName("BOOK", "AUTHOR_ID").equal("AUTHOR", "ID"))
.where(fieldByName("BOOK", "PUBLISHED_IN").equal(1948))
.getSQL();
It also references to the manual's section about using jOOQ for "plain SQL":
http://www.jooq.org/doc/2.6/manual/sql-building/plain-sql/
Of course, you can still use the code generator to generate meta information for your schema. This doesn't mean that you will have to add a runtime dependency on the generator, as the generator is only used at compile-time
2 Comments
fieldByName? I'm using jooq 3.0.1 and I found out that fieldByName can actually be found in Factory class in lower versions. But when I switch to lower version (2.6.4), I can't use the DSL class.DSL.fieldByName()