Solved

how to bind array to a prepared statement in JDBC

Posted on 2008-06-23
3
845 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
Comment Utility
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
Comment Utility
that is surprising! do you generally just build a stringbuffer with the (...)  contents?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:-)

>>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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now