commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc Esher (4-2060)" <>
Subject RE: in() statements
Date Thu, 16 Sep 2004 18:09:35 GMT
Thanks for responding.  

That's how I had it initially, but queryrunner didn't like it. So I just
decided to not call queryrunner as a preparedstatement and just build
the sql straight up and pass queryrunner the full sql statement.  

-----Original Message-----
From: Rhino [] 
Sent: Thursday, September 16, 2004 2:03 PM
To: Jakarta Commons Users List
Subject: Re: in() statements

I haven't used QueryRunner but what you're doing looks like standard SQL
me. That means that using in() should work for queries *regardless* of
number of parameters you are passing to the in().

For example,

    select * from table where myIDField IN(3)

should work just as well as

    select * from table where myIDField IN(1,3)

Give that a try first before trying to get into anything too fancy.


----- Original Message ----- 
From: "Marc Esher (4-2060)" <>
To: <>
Sent: Thursday, September 16, 2004 12:33 PM
Subject: in() statements

Hi All,

  I'm trying to use QueryRunner to run an in() statement and I'm having

I can't find anything in the javadocs about how to do this, and I'm not
familiar enough with prepared statements in general to intelligently
figure this out.

I'm determining dynamically whether I want to use an "=" statement or an
in() statement depending on the number of parameters passed to my

Let's say it's like this:

String select = "Select * from table where " ;

If params.length ==1

  whereClause=  " myIDfield=?"


  whereClause=" myIDField IN(?)"

String sql = select + where;

I then pass a string as my input parameter to queryrunner. This works
fine when there's just one parameter and I'm using "=", but if I use
IN(), I get an error.

My sql is evaluating to "select * from table where myIDField IN(1,3)",
but query runner doesn't like it because it can't convert "1,3" to an

So the question is, 1) is there an easier way to do this that I'm
missing?  2) if not, then how do I accomplish this task? Do I need to
use separate ? for each parameter in my in statement?

Thanks a million!


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message