| 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
|
|
|
One doesn't. It is impossible to make that work.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26144
|
|
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
|
 |
 |
|
|
subject: Comma seperated binding variable in PreparedStatement
|
|
|