如何使用JOOQ从模板和参数占位符生成sql? [英] How to generate sql from template and param placeholder with JOOQ?

查看:123
本文介绍了如何使用JOOQ从模板和参数占位符生成sql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过jOOQ 3.11.11获得了这样的sql模板.

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

我存储纯SQL模板.

I store the plain sql template.

select * from table1 where report_date = :bizdate

参数"bizdate"由实时查询决定.
所以.如何生成真实的sql

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

select * from table1 where report_date = '20190801'

具有存储的sql模板字符串和实时输入日期'20190801'.

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

推荐答案

您可以使用此

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

请参见 DSLContext.resultQuery(String, QueryPart...)

这篇关于如何使用JOOQ从模板和参数占位符生成sql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆