2

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?

5
  • 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? Commented Nov 9, 2012 at 11:09
  • We want to create a database via invoking stored procedure. Commented 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 details Commented 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 string Commented Nov 22, 2012 at 21:21
  • @skowron-line: Maybe, although I'm still not sure how they want to "create a database" with jOOQ... Commented Nov 23, 2012 at 14:26

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

This might sound stupid but, where is the method definition of 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.
@onepotato: Here's the 2.x -> 3.x migration guide: jooq.org/doc/3.0/manual/reference/migrating-to-3.0. The method is right there, in DSL.fieldByName()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.