I am doing a query like this:
Query query = PlatoonApp.getEntityManager().createQuery(
"SELECT c FROM Client c WHERE c.type1 LIKE ? or c.type2 LIKE ? or c.type3 LIKE ?" +
" or c.type4 LIKE ? ORDER BY c.type", Client.class);
query.setParameter(1, legalStrQuery + "%");
query.setParameter(2, legalStrQuery + "%");
query.setParameter(3, individualStrQuery + "%");
query.setParameter(4, individualStrQuery + "%");
query.setFirstResult(startPosition);
if (maxResults != 0)
query.setMaxResults(maxResults);
return (List<Client>) query.getResultList();
This is the query. I have some rows with information using "´", "~" and these characters are getting replaced. Why is it happening?
Escape the single quote by adding another single quote before it, eg '
would become ''
.
I don't think that the ~
is an illegal character, it's just the single quote that's hanging you up.
Note: I think you can replace all of the single quotes with the following regex, (?!<')['](?!')
so you can do something like..
stringInstance.replaceAll( "(?!<')['](?!')", "''" );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.