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 '%?%'
Assuming that the query is run using a PreparedStatement, the problem is probably that queryForList calls setString(1, 'some descr'). This would resolve the SQL to "... and descr LIKE %'some descr'%".
Try altering the code to:
queryWhere.append("and descr LIKE ?");
...
.setString(1, "%some descr%")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With