Solved

how to bind array to a prepared statement in JDBC

Posted on 2008-06-23
3
852 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

626 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