我需要在我的查询生成器的有子句中给我们一个占位符。我尝试使用“?” 标记,但后来我得到:
java.sql.SQLException: argument holder index 1 not valid, only 1 in statement
这是我试图完成的事情:
QueryBuilder<ArchiefTag, Integer> archiefTagQb = helper
.getArchiefTagDao().queryBuilder();
tagSelectArg = new SelectArg();
archiefTagQb.where().in(ArchiefTag.TAG_FIELD, tagSelectArg);
archiefTagQb.groupBy(ArchiefTag.ARCHIEF_ENTRY_FIELD);
QueryBuilder<ArchiefEntry, Date> archiefEntryQb = helper
.getArchiefEntryDao().queryBuilder();
archiefEntryQb.join(archiefTagQb);
//the having must be on the outer join query. Don't know why
archiefEntryQb.having(String.format("COUNT(%s) = ?",ArchiefTag.TAG_FIELD));
preparedGetArchiefForTags = archiefEntryQb.prepare();
生成的sql为:
SELECT `ARCHIEF_ENTRY`.*
FROM `ARCHIEF_ENTRY`
INNER JOIN `ARCHIEF_TAG` ON `ARCHIEF_ENTRY`.`id_entry` = `ARCHIEF_TAG`.`entry`
GROUP BY `ARCHIEF_TAG`.`entry`
HAVING COUNT(tag) = ?
但是当我打电话时:
preparedGetArchiefForTags.setArgumentHolderValue(1, 3);
发生上述异常。
任何想法如何解决这个问题?