How to generate sql from template and param placeholder with JOOQ?

不羁的心 提交于 2019-12-11 15:54:26

问题


I get the sql template like this with jOOQ 3.11.11.

DSLContext context = new DefaultDSLContext(conf);
Query query = context.select().from("table1").where(DSL.field("report_date").eq(DSL.param("bizdate")));
String sqlTemp = context.renderNamedParams(query);

I store the plain sql template.

select * from table1 where report_date = :bizdate

The param 'bizdate' is decided by realtime query.
So. How to generate the real sql

select * from table1 where report_date = '20190801'

with the stored sql template string and the realtime input date '20190801'.


回答1:


You can use this:

context.resultQuery(sqlTemp, DSL.param("bizdate", "20190801")).fetch();

See DSLContext.resultQuery(String, QueryPart...)



来源:https://stackoverflow.com/questions/57588198/how-to-generate-sql-from-template-and-param-placeholder-with-jooq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!