Java Jooq-普通SQL参数化数组/列表
我想在“in”参数中提供集合/数组,但我得到了 当我使用数组时:Java Jooq-普通SQL参数化数组/列表,java,mysql,jdbc,jooq,Java,Mysql,Jdbc,Jooq,我想在“in”参数中提供集合/数组,但我得到了 当我使用数组时: org.jooq.exception.SQLDialectNotSupportedException: Cannot bind ARRAY types in dialect MYSQL 当我使用列表时: org.jooq.exception.SQLDialectNotSupportedException: Type class java.util.Arrays$ArrayList is not supported in
org.jooq.exception.SQLDialectNotSupportedException: Cannot bind ARRAY types in dialect MYSQL
当我使用列表时:
org.jooq.exception.SQLDialectNotSupportedException: Type class java.util.Arrays$ArrayList is not supported in dialect DEFAULT
以下是我的简单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
我是这样执行的
dslContext.fetch(sql, val(fooId), val(someIds))
.into(Summary.class);
使用单绑定变量无法做到这一点(使用数组的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
然后
dslContext.fetch(sql,
val(fooId),
DSL.list(someIds.stream().map(DSL::val).collect(toList())))
.into(Summary.class);
另见