ric*_*oon 4 java mysql jdbc jooq
我想在“IN”参数中提供集合/数组,但我得到了
当我使用数组时:
org.jooq.exception.SQLDialectNotSupportedException: Cannot bind ARRAY types in dialect MYSQL
Run Code Online (Sandbox Code Playgroud)
当我使用列表时:
org.jooq.exception.SQLDialectNotSupportedException: Type class java.util.Arrays$ArrayList is not supported in dialect DEFAULT
Run Code Online (Sandbox Code Playgroud)
这是我的普通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
Run Code Online (Sandbox Code Playgroud)
这是我如何执行它
dslContext.fetch(sql, val(fooId), val(someIds))
.into(Summary.class);
Run Code Online (Sandbox Code Playgroud)
你不能用单个绑定变量来做到这一点(除了在带有数组的 PostgreSQL 中)。但是您可以在 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
Run Code Online (Sandbox Code Playgroud)
进而
dslContext.fetch(sql,
val(fooId),
DSL.list(someIds.stream().map(DSL::val).collect(toList())))
.into(Summary.class);
Run Code Online (Sandbox Code Playgroud)
也可以看看 DSL.list(QueryPart...)
| 归档时间: |
|
| 查看次数: |
1077 次 |
| 最近记录: |