Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set list of parameters on prepared statement? [duplicate]

i have a list of names e.g.:

List<String> names = ... names.add('charles'); ... 

and a statement:

PreparedStatement stmt =    conn.prepareStatement('select * from person where name in ( ? )'); 

how to do the following:

stmt.setParameterList(1,names); 

Is there a workaround? can someone explain why this method is missing?

using: java, postgresql, jdbc3

like image 605
Chris Avatar asked Aug 20 '09 10:08

Chris


People also ask

Can I use same prepared statement multiple times?

Once a PreparedStatement is prepared, it can be reused after execution. You reuse a PreparedStatement by setting new values for the parameters and then execute it again.

What is prepared statements with parameterized queries?

In database management systems (DBMS), a prepared statement, parameterized statement, or parameterized query is a feature used to pre-compile SQL code, separating it from data. Benefits of prepared statements are: efficiency, because they can be used repeatedly without re-compiling.


1 Answers

This question is very old, but nobody has suggested using setArray

This answer might help https://stackoverflow.com/a/10240302/573057

like image 161
earcam Avatar answered Sep 28 '22 03:09

earcam