• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comma seperated binding variable in PreparedStatement

 
Ajju Chawla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21551
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One doesn't. It is impossible to make that work.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35269
383
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ajju Chawla
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne & Paul,

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

Thanks again guys..

-Aj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic