jooq 返回具有错误值的查询
我想使用以下基于 jooq 的代码插入数据库表数据来生成查询:
Factory jf = getJooqFactory();
int surveyId = jf.nextval(SURVEY_ID_SEQ).intValue();
jf.insertInto(SURVEY)
.set(SURVEY.ID, surveyId)
.set(SURVEY.NAME, survey.getName())
.set(SURVEY.IDML, Factory.val(idml, SQLDataType.CLOB))
.execute();
问题是,当我使用此代码打印查询时,
System.out.println(jf.insertInto(SURVEY)
.set(SURVEY.ID, null)
.set(SURVEY.NAME, null)
.set(SURVEY.IDML, null)
.getSQL());
我得到的是带有问号而不是值的查询。
insert into "collect"."survey" ("id", "name", "idml") values (?, ?, ?)
当我单独打印变量的值时,它们都是正确的。即使我在 .set() getSQL() 中手动插入字符串值也会返回问号。
I want to insert into database table data using following jooq based code to generate query:
Factory jf = getJooqFactory();
int surveyId = jf.nextval(SURVEY_ID_SEQ).intValue();
jf.insertInto(SURVEY)
.set(SURVEY.ID, surveyId)
.set(SURVEY.NAME, survey.getName())
.set(SURVEY.IDML, Factory.val(idml, SQLDataType.CLOB))
.execute();
The problem is that when I print the query using this code
System.out.println(jf.insertInto(SURVEY)
.set(SURVEY.ID, null)
.set(SURVEY.NAME, null)
.set(SURVEY.IDML, null)
.getSQL());
what I get is query with question marks instead of values.
insert into "collect"."survey" ("id", "name", "idml") values (?, ?, ?)
When I print values of variables separately they are all correct. Even if I insert String values manually in .set() getSQL() return question marks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
org.jooq.Query.getSQL( )
呈现 SQL 的方式与呈现给 JDBC 的方式完全相同PreparedStatement
。 Java 中的准备语句期望绑定变量呈现为问号:?
。然后使用方法设置实际的绑定值,如本例所示。如果您想查看生成的带有内联绑定值的 SQL,您可以使用工厂的
Factory.renderInlined()
方法:Query
对象上还有一个getSQL(boolean)
方法,用于使用内联绑定变量呈现 SQL:了解有关 JDBC 的
PreparedStatement
的更多信息这里:http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html
org.jooq.Query.getSQL()
renders SQL exactly as it is rendered to the JDBCPreparedStatement
. Prepared statements in Java expect bind variables to be rendered as question marks:?
. The actual bind values are then set using methods, such as in this exampleIf you want to see the generated SQL with inlined bind values, you can use the factory's
Factory.renderInlined()
method:There is also a
getSQL(boolean)
method on theQuery
object, to render SQL with inlined bind variables:Learn more about JDBC's
PreparedStatement
here:http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html