Have following String built SQL query:
StringBuilder querySelect = new StringBuilder("select * from messages ");
StringBuilder queryWhere = new StringBuilder("where msg_id=?");
if (fileRSVO.getFileName()!= null){
queryWhere.append("and descr LIKE %?% ");
}
querySelect.append(queryWhere);
List<Map<String, Object>> list = getJdbcTemplate().queryForList(querySelect.toString(), params.toArray());
...
The problem is in this part:
queryWhere.append("and descr LIKE %?% ")
LIKE doesn’t work.
Checked in debug – it’s added to all query.
Should it be single quoted or some other trick?
thanks.
EDITED
tried single quotes:queryWhere.append("and descr LIKE '%?%' ")
doesn’t work
here is debug string:
select * from messages where msg_id=? and descr LIKE '%?%'
?is not a placeholder for textual substitution, it’s a parameter (i.e. it’s like variable in Java), therefore it should be treated as a separate token. This should work, but perhaps not in all databases:Alternativelty you can pass
%s as parts of parameter value, as suggested by Justin Muller.