简体   繁体   中英

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM