![]() |
![]() |
|
| Index | Recent Threads | Unanswered Threads | Who's Online | Help |
|
|
| No member browsing this thread |
|
Thread Status: Active Total posts in this thread: 5
|
|
| Author |
|
|
Member Joined: Aug 8, 2007 Post Count: 55 Status: Offline |
Hello, Consider this simple SQL statement that selects all Cars that are red, blue, or green: select * from CAR where color in ('red', 'blue', 'green');Now, assume that I want the equivalent query using JDOQL, plus the number of parameters in the "in" clause can be variable -- for example, one query may look for just 'red' while another might look for 'red', 'blue', and 'green'. How would this query look in JDOQL, especially if I use it a NamedQuery, and how would I specify the parameters? I'm guessing something like this: select from com.mydomain.Car where color == :colorBut how do I specify the mutiple parameter values? Thank you!! -Ryan |
||
|
|
Expert Joined: Nov 16, 2005 Post Count: 1008 Status: Online |
Hello, Consider this simple SQL statement that selects all Cars that are red, blue, or green: select * from CAR where color in ('red', 'blue', 'green');Now, assume that I want the equivalent query using JDOQL, plus the number of parameters in the "in" clause can be variable -- for example, one query may look for just 'red' while another might look for 'red', 'blue', and 'green'. How would this query look in JDOQL, especially if I use it a NamedQuery, and how would I specify the parameters? I'm guessing something like this: select from com.mydomain.Car where color == :colorBut how do I specify the mutiple parameter values? Thank you!! -Ryan Declare color to be a java.util.Collection and call query.execute(c) where c is filled with the requested values Guido ---------------------------------------- Guido Anzuoni http://www.objectmagic.org |
||
|
|
Member Joined: Aug 8, 2007 Post Count: 55 Status: Offline |
Thanks Guido, I was hoping it was something like that. Since I prefer to use named query parameters (like :color in the JDOQL) can I do something like this: Collection colors = new ArrayList();Is this correct? Thank you!! |
||
|
|
Expert Joined: Nov 16, 2005 Post Count: 1008 Status: Online |
Thanks Guido, I was hoping it was something like that. Since I prefer to use named query parameters (like :color in the JDOQL) can I do something like this: Collection colors = new ArrayList();Is this correct? Thank you!! Yes Guido ---------------------------------------- Guido Anzuoni http://www.objectmagic.org |
||
|
|
Newbie USA Joined: Jun 28, 2010 Post Count: 2 Status: Offline |
I was never able to get the above syntax to work. I always received the error: Parameter "color" was specified as java.util.ArrayList but should have been java.lang.String However this syntax did work... qry.setFilter(":color.contains(color)"); ---------------------------------------- KC Berg |
||
|
|
|
|
|
Current timezone is GMT May 17, 2012 11:45:04 AM |