Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 868
  • Last Modified:

how to bind array to a prepared statement in JDBC

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
jeffmc033
Asked:
jeffmc033
  • 2
1 Solution
 
CEHJCommented:
The short answer is - you can't. You need to build up the set 'manually' and use an ordinary statement
0
 
jeffmc033Author Commented:
that is surprising! do you generally just build a stringbuffer with the (...)  contents?
0
 
CEHJCommented:
:-)

>>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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now