问题
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