Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LIKE operator

 
Faraz Ali
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't want to append the '%' directly to the name variable, when calling setParameter ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic