aspose file tools
The moose likes JDBC and the fly likes Comma seperated binding variable in PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Comma seperated binding variable in PreparedStatement" Watch "Comma seperated binding variable in PreparedStatement" New topic
Author

Comma seperated binding variable in PreparedStatement

Ajju Chawla
Greenhorn

Joined: Oct 21, 2005
Posts: 21
Hi,

When using JDBC PreparedStatements, binding variables are very simple to assign to each "?" in a SQL statement.

How does one assign binding variable which is seperated by comma to a SQL statement within an "IN" clause?

// code start
String strValues = "1,2,3";

UPDATE ....
WHERE .... IN (?)

pstmt.setString(1,strValues);

pstmt.executeUpdate();

// code ends

Execution of the above gives me SQL exception...Invalid Number...


How does one assign the values within the IN clause?

Thanks
-Aj
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16479
    
    2

One doesn't. It is impossible to make that work.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26144
    
  66

Ajju,
Start out with using a PreparedStatement and building the SQL each time. This will result in some of the PreparedStatements being in the cache (when the same # of in clause parameters are present.) If you find you have a performance problem due to exceeding cache size, see this JavaRanch Journal article.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ajju Chawla
Greenhorn

Joined: Oct 21, 2005
Posts: 21
Hi Jeanne & Paul,

Thanks for the info...I got that.
Jeanne, that article was good...

Thanks again guys..

-Aj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comma seperated binding variable in PreparedStatement
 
Similar Threads
Anonymous Classes & Exception Handling
Query In Clause
delete multiple records using checkboxes
Using Struts 2 Select Tag for dynamic values
how to convert .csv files into sql server files using java