You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by sbelt <sb...@velos.com> on 2002/02/25 19:58:24 UTC

How to create a single statement with unknow number of criterion connected by OR

I have a method which fetches several records based on record Id's. Using
the peers howto, I see the .or() method used when I know all the criterion
in advance; but what if I am dynamically or'ing the criterion?

Perhaps the excerpt below explains better what I am trying to do:

Criteria criteria = new Criteria();
// hard coded for testing. In my method, Vector v is a passed parameter
Vector v = new vector
v.put("32");
v.put("68");
v.put("98");

if ( v.size() > 0 )
    critieria.add( v.get(0) );
for ( int x = 1; x < v.size(); x++ )
{
    Criteria.Criterion c = criteria.getNewCriterion(myDataPeer.X1,
                                            v.get(x), Criteria.EQUALS);
    criteria = criteria.or(c); // <-- does this work???
}

My code above should create the SQL
    SELECT FROM ? WHERE X1='32' OR X1='68' OR X1='98';

I am just not sure of what my "append" statement (as indicated in my
example)
should be. Could someone help?

TIA,

Steve B.





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>