[英]Jooq - Plain SQL Parameterized Array/List
I would like to supply collection/arrays in the "IN" parameter but I got 我想在“IN”参数中提供集合/数组,但我得到了
When I used array: 当我使用数组时:
org.jooq.exception.SQLDialectNotSupportedException: Cannot bind ARRAY types in dialect MYSQL
When I used list: 当我使用列表时:
org.jooq.exception.SQLDialectNotSupportedException: Type class java.util.Arrays$ArrayList is not supported in dialect DEFAULT
Here is my plain sql: 这是我的简单sql:
String sql = "SELECT SUM(foo.reply = 'Y') yes " +
"FROM foo " +
"LEFT OUTER JOIN bar " +
"ON foo.id = bar.foo_id " +
"WHERE " +
"foo.id = ? " +
"AND foo.some_id IN (?) "; //this is the part I would like to use array or list
Here's how I execute it 这是我执行它的方式
dslContext.fetch(sql, val(fooId), val(someIds))
.into(Summary.class);
You can't do that with single bind variables (except in PostgreSQL with arrays). 你不能用单个绑定变量做到这一点(除了带有数组的PostgreSQL)。 But you can use nested plain SQL query parts in jOOQ as such:
但是您可以在jOOQ中使用嵌套的纯SQL查询部分:
String sql = "SELECT SUM(foo.reply = 'Y') yes " +
"FROM foo " +
"LEFT OUTER JOIN bar " +
"ON foo.id = bar.foo_id " +
"WHERE " +
"foo.id = {0} " +
"AND foo.some_id IN ({1}) "; // Use the {0}, {1} placeholders
And then 然后
dslContext.fetch(sql,
val(fooId),
DSL.list(someIds.stream().map(DSL::val).collect(toList())))
.into(Summary.class);
See also DSL.list(QueryPart...)
另请参见
DSL.list(QueryPart...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.