单引号内指定的参数没有被替换

问题描述 投票:0回答:1

我试图用一个已命名的参数,但是当我让他们单引号内他们不会被替换的查询,并返回0的结果。如何使用我的参数中的单引号里面?

protected static final String SQL_QUERY =
        "    SELECT * \n" +
        "    FROM example \n" +
        "    WHERE UPPER(name) LIKE UPPER('%:query%') \n";

@Autowired
private NamedParameterJdbcTemplate template;

public List<Item> getResultFromQuery(String query) throws Exception {
return (List<Item>) template.query(SQL_QUERY,
                    new MapSqlParameterSource().addValue("query", query), resultSetExtractor);
}
java sql oracle named-parameters
1个回答
0
投票

可能是你使用的是单引号内\ -N,你需要封装\ n和用于表达“%:查询%”,你可以把它写为...“+%:查询%+”单qutations内,也可以是“ “+%:查询%+”'

© www.soinside.com 2019 - 2024. All rights reserved.