SQL 使用单引号查询 spring jdbctemplate

SQL query with single quotes using spring jdbctemplate

我试图使用 jdbctemplate 来 运行 对 Postgres 数据库的查询,并且查询中包含带有动态值的单引号。准备好的语句是不是可以替换?使用单引号内的值。请建议是否有任何方法可以逃脱或准备好的语句替换这些值。

select * from test where xpath('/a:name/a:first/text()=?', xml);

?在上面的查询中应该用 "testuser"

之类的值替换

谢谢。

无法识别字符串文字中的参数。

因此将参数移出字符串。并且比较后的值需要加引号。

select * from test where xpath('/a:name/a:first/text()=''' || ? || '''', xml);