File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes passing values with IN attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "passing values with IN attribute" Watch "passing values with IN attribute" New topic

passing values with IN attribute

Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

I have a where clause like:"WHERE IB.CURR_CUSTOMER_KEY IN (?)"
Now input values may contain one or more then one values. And the number of customer key can only decided at runtime only so how to pass values in IN attribute.
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
If your are using prepared statement, u can use
setString(int parameterIndex, String x)

where string x = "Value1,Value2" and parameterIndex = 1
The string x u need to create at runtime.

So ur IN clause will be
Select * from xyz where in ("Value1,Value2")

What do u thing
Am i on right track

Let me know

Makarand Parab
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

That won't work. You can only substitute a single string literal for the parameter. So the database would try to match on "Value1,Value2" rather than "Value1" and "Value2."

Take a look at this thread where I explain select batching a bit. Interestingly, this is the topic of an article for the October JavaRanch Journal. The article will go into more depth on the topic, walk through an example and point out some criteria to use.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: passing values with IN attribute
It's not a secret anymore!