Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1091147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:28:46+00:00 2026-05-16T23:28:46+00:00

In JDBC I can use question marks for query parameters, like this: SELECT *

  • 0

In JDBC I can use question marks for query parameters, like this:

"SELECT * FROM users WHERE login = ?"

and then

ps.setString(1, "vasya");

But how can I query for list of logins:

"SELECT * FROM users WHERE login IN ?"

suppose, I have

List<String> logins = ...

What should I type there:

ps.setWhat(1, what);

I could rewrite query as:

"SELECT * FROM users WHERE login = ? OR login = ? OR login = ?"

and then call setString in loop, but I’d like to know if it is possible to pass a set of elements as single param in query.

Maybe there are vendor-specific extensions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:28:47+00:00Added an answer on May 16, 2026 at 11:28 pm

    There are vendor specific ways to do that, therefore it would be good to know what database you use. I know solutions for PostgreSQL and H2. I implemented this feature in the H2 database, so that’s what I know best:

    H2 Database

    PreparedStatement prep = conn.prepareStatement(
      "select * from users where login in (select * from table(x int = ?))");
    prep.setObject(1, new Object[] { "1", "2" });
    ResultSet rs = prep.executeQuery();
    

    PostgreSQL

    WHERE login = ANY(?)
    

    Then set the parameter to an array of values using PreparedStatement.setArray(..) (not setObject as for H2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to write a single JDBC statement that can handle the equivalent of
This is a simple question: I know and have heard from almost everyone that
I know this is probably a dumb question but I can't figure it out
Newbie question here... I need to select an JDBC driver to connect an application
I am trying to use DBUnit with plain JDBC and HSQLDB, and can't quite
I know this is a basic question, but I can't seem to find an
I use PostgreSQL 8.4, but i think my question can be expanded to most
Note: I've looked at this question: Preventing SQL injection without prepared statements (JDBC) .
QUESTION: can YOU use multiple statements and recordset, which operate simultaneously, using the same
In java-jdbc, I can easily run the following SQL (NOTE the double quotes around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.