Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to bind array to a prepared statement in JDBC

Posted on 2008-06-23
3
Medium Priority
?
854 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

715 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