res1
res1

Reputation: 3660

Jooq for creating jasper reports queries

Can i use jooq to create queries for jasper report?

I mean query like this

select something from table where field=$P{someparameter}

the problem is the $P{someparameter} in the generated sql.

To be clear I just need the generated sql query.

Upvotes: 1

Views: 349

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220977

You can always resort to what jOOQ calls "plain SQL", if there is some vendor-specific SQL expression that you would like to include. In your case, I'm guessing that the following might be sufficient for you:

Select<?> select =
DSL.using(configuration)
   .select(TABLE.SOMETHING)
   .from(TABLE)
   .where(TABLE.FIELD.eq(DSL.field("$P{{someparameter}}", TABLE.FIELD.getDataType())));

Note that you'll have to "escape" the curly braces, as curly braces have a meaning in jOOQ's plain SQL template language.

You can then extract the SQL string like this:

String sql = select.getSQL();

And possibly extract the bind values as well:

List<Object> bindings = select.getBindValues();

Upvotes: 1

Related Questions