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 7037547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:33:31+00:00 2026-05-28T01:33:31+00:00

I am trying to use a SQL Select statement for a query in Java.

  • 0

I am trying to use a SQL Select statement for a query in Java. I currently have the following:

ResultSet rs = stmt.executeQuery("SELECT *" +
                                             " FROM " + table + 
                                             " WHERE " + selection + 
                                             " VALUES " + selectionArgs);

where “selection” is a string and “selectionArgs” is a string array.

 String selection = "documentFK=?";
 String[] selectionArgs = { ... };

Is it possible to use the VALUES command to replace the ? like in with the INSERT command? Either way, what would be the correct syntax?

Thanks for the help.

  • 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-28T01:33:32+00:00Added an answer on May 28, 2026 at 1:33 am

    no, that is not the way it’s done. first you create the statement from the query, using the question marks as place holders for the real values you want to put there. then you bind these values to the statement.

    //the query
    String sql = "SELECT " + "*" +
                    " FROM " + table + 
                    " WHERE documetFK = ?";
    
    //create the statement
    PreparedStatement stmt = connection.prepareStatement(sql);
    
    //bind the value
    stmt.setInt(1, 4); //1 is "the first question mark", 4 is some fk
    
    //execute the query and get the result set back
    ResultSet rs = stmt.executeQuery();
    

    now, if you want this thing with selection string and some args, then you’re going to have a loop in your java code. not sure what your array looks like (you’re not giving me that much to go on), but if it’s made up from strings, it would be something like this:

    //the query
    String sql = "SELECT " + "*" +
                    " FROM " + table + 
                    " WHERE " + selection;
    
    //create the statement
    PreparedStatement stmt = connection.prepareStatement(sql);
    
    //bind the values
    for(int i = 0; i < selectionArgs.length; i++) {
        stmt.setString(i, selectionArgs[i]); //i is "the nth question mark"
    }
    
    //execute the query and get the result set back
    ResultSet rs = stmt.executeQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a CASE statement in a SQL query I have and
I'm trying to use LINQ to SQL to select a few specific columns from
While trying to use LINQ to SQL I encountered several problems. I have table
I have a SQL query which retrieve wall post list $qry=mysql_query(SELECT senderid,post,date FROM .post_table.
I'm trying to use SQL Server 2000 DTS Package to download a file from
I am trying to use a SQL Server 2008 Ranking Function on a query
I am trying to write a sql statement that I have 2 tables Store
I have got the following SQL statement (SQL Server): DECLARE @atr nvarchar(255), @con nvarchar(1000),
I'm trying to figure out how to exclude items from a select statement from
I have a simple SQL query (SQL Server 2005) where I'm selecting from a

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.