全文搜索和可变绑定使用Postgres和JOOQ不起作用



我正在尝试使用JOOQ在Postgres数据库中进行全文搜索。以下行有效:

Result res = pgContext.select()
                      .from(products.PRODUCTS)
                      .where("to_tsvector(title || ' ' || description || ' ' || tags) @@ to_tsquery('" + query + "')")
                      .fetch();

但是,当我添加可变绑定时,以防止SQL注入,我不再获得结果:

Result res = pgContext.select()
                      .from(products.PRODUCTS)
                      .where("to_tsvector(title || ' ' || description || ' ' || tags) @@ to_tsquery('?')", query)
                      .fetch();

有什么想法?

谢谢和美好的一天

,因为@posz没有将他的评论作为答案,而且已经有一段时间了,我将他的答复作为清晰的答案。

尝试... to_tsquery(?)... - 绑定标记?在内部无法工作 字面。

最新更新