|
First floor Q: |
|
|
Hi, I ' m trying to use the AS statement with JPA. What I want to does is get all of the items that has a name that matchs the keyword ' og ' For example (' Dog ', ' Big dog ' ...). If I Write this: query = Em.createquery ("Select I from Item i WHERE i.name like:keyword"); Query.setparameter ("keyword", keyword); That'll take the items and that has the exact keword (in my example only ' og ' would appear). I ' ve tried to use the wildcards%uh ID doesn ' t work: query = Em.createquery ("Select I from Item i WHERE i.name Like '%:keyword% '); Query = Em.createquery ("Select I from Item i WHERE i.name like%:keyword%"); Does Anybody knows how do I use the like statement with wildcards? And by the the-the-there a-ignore the case of my keyword (' og ' or ' og ' should give the same result). Thanks, Antonio goncalves |
|
|
|
Second floor: |
|
|
Hello Antonio,
Can Don't use query = Em.createquery ("Select I from Item i WHERE UPPER (i.name) like UPPER (: keyword)"); Query.setparameter ("keyword", "%" keyword "%"); Query.getresultlist ();
Best regards, Chris |
|
|
|
|
Third floor: |
|
|
Hi Chris. It doesn ' t work with the UPPER keyword. Here's the error that I ' ve got:
caused By:exception [TOPLINK-8025] (Oracle TOPLINK Essentials-2006.4 (Build 060412)): oracle.toplink.essentials.except Ions. Ejbqlexception Exception description:syntax Error parsing the query [SELECT i from Item i WHERE UPPER (i.name) like UPPER (: keyword) ORDER by I.name], unexpected tokens [like]. |#]
Any idea?
Otherwise, the wildcard works fine:
query = Em.createquery ("Select I from Item i WHERE i.name like:keyword"); Query.setparameter ("keyword", "%" keyword "%"); Query.getresultlist (); |
|
|
|
|
Level four: |
|
|
Hello, Sorry, looks like I w As wrong on the UPPER (: Keword) portion. The spec states: String_Expression [not] like Pattern_value [ESCAPE Escape_character] "The Pattern_value is a stri ng literal or a string-valued input parameter " so you'll have to call toUpperCase () on the string you pass into The query IE: query.setparameter ("keyword", "%" keyword.touppercase () "%"); Best regards, Chris |
|
|
|
|
Final wording: |
|
|
Thanks, it works fine like that
query = Em.createquery ("Select I from Item i WHERE UPPER (i.name) Like:keyword ORDER by I.name"); Query.setparameter ("keyword", "%" + keyword.touppercase () + "%");
Antonio |
|
|
My error wording: Sql.append ("and s.idcard like%?%"); Paraml.add (Stuff.getidcard (). Trim ());
The right should be: Sql.append ("and s.idcard like?");
Paraml.add ("%" +stuff.getidcard (). Trim () + "%");
Transferred from: http://forums.oracle.com/forums/thread.jspa?threadID=423742