Solved

how to bind array to a prepared statement in JDBC

Posted on 2008-06-23
3
848 Views
Last Modified: 2010-04-21
I have a SQL statement as such:

 select * from User where usder_id IN (?)

I'm using the PreparedStatement class and I dont see an obvious wat to bind my java.util.List of ids.
The closest I found is PreparedStatement.setArray(index, java.sql.Array)
But it is not clear what implementation class I can use for that call (since java.sql.Arrayis an interface)

Please advise. thanks!
0
Comment
Question by:jeffmc033
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 21847438
The short answer is - you can't. You need to build up the set 'manually' and use an ordinary statement
0
 

Author Closing Comment

by:jeffmc033
ID: 31469811
that is surprising! do you generally just build a stringbuffer with the (...)  contents?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21857229
:-)

>>that is surprising!

Well yes and no. If you think about it, a PreparedStatement works on the principle of known and finite parameters. The only variable is the magnitude of the parameter. The statement can be given anything (including nothing) in a set

>>do you generally just build a stringbuffer with the (...) contents?

Exactly. StringBuilder for recent Java versions
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question