-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Query using LIKE clause and involving special characters
PostPosted: Wed Jun 20, 2012 3:37 pm 
Newbie

Joined: Tue Apr 10, 2012 2:57 pm
Posts: 8
Hello,

I am trying to do the following query:

Code:
items.addAll(createQuery("from "+ Item.class.getName()   + " where (lower(TAGS) like :tag) order by id desc").setParameter("tag", '%' + tags[i] + '%').getResultList());


This essentially means that I might be having TAGS where there will be '_', '%', '$', or any other special characters embedded/prefixed/suffixed to a word. When I execute my query, I get wrong results (all the items in database, not specific items). I understand that '_' and '%' are wildcard characters, but surely there is a way to escape it.

I tried to use the ESCAPE predicate but it didn't work as well.

How can I resolve the problem?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.