wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes LIKE operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "LIKE operator" Watch "LIKE operator" New topic
Author

LIKE operator

Faraz Ali
Ranch Hand

Joined: May 15, 2008
Posts: 108
Hi,

I want to create a named query, which will return all the names which starts with "ABC", similar to the query below:
select * from customer where name like 'ABC%'

or, if i the string 'ABC' is stored in a variable, than above query becomes:
select * from customer where name like name+'%'

I write a named query like this:
select c from customer c where name like :name

its working, but its not waht i want, when i changed the above named query to below:
select c from customer c where name like :name%

Above query gives exception. How to do such thing?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You don't want to append the '%' directly to the name variable, when calling setParameter ?


[My Blog]
All roads lead to JavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: LIKE operator
 
Similar Threads
How to do optional wildcard select in JPA named queries?
Conditions for dependent entites on fetching?
entity loading blues
listing hibernate named queries from java
urgent help reqd