aspose file tools*
The moose likes JDBC and the fly likes Problem with IN clause Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem with IN clause " Watch "Problem with IN clause " New topic
Author

Problem with IN clause

sreedhar Lackka
Ranch Hand

Joined: Jul 05, 2008
Posts: 154
Hi,

Thanks in advance.
I would like to pass a comma separated string to my stored procedure. When I send a single value it is working correctly however If I pass more than one it is not returning any parameter in JDBC.
Example:
I have a select query which uses in like ‘select name from where roll_no in (‘10a’,’10e’,’11j’);
I have java variable to hold this comma separated value.

Please guide me.

Thanks,
Sree
Mike Zal
Ranch Hand

Joined: May 04, 2011
Posts: 144

Can you post the code you are using so far?


OCJP6, OCWCD5
sreedhar Lackka
Ranch Hand

Joined: Jul 05, 2008
Posts: 154
Hi,
Thanks for your reply.

The high level code looks like below,


The proc will accept this in parameter, and perform select with in caluse

select name from xsdr where num in (varName)

here varName is the value sent from Java

Thanks
Sree

Mike Zal
Ranch Hand

Joined: May 04, 2011
Posts: 144

After your call on line 3, the StringBuffer contains "11B10A". If you intended to have them comma separated you need to append that as well


I'm not sure how stored procedure will react to the comma separated list; you may want to try testing it from the database command line. You might want to consider overloading the test_proc procedure to take an Array of values instead of trying to stuff multiple values into one varchar parameter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with IN clause