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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:05:35+00:00 2026-05-27T05:05:35+00:00

I’m struggling with a homework assignment and am getting hung up on some SQL

  • 0

I’m struggling with a homework assignment and am getting hung up on some SQL queries.

My query is interrogating an inventory database for the quantity of some item. The query requests the column with the name quantity_in_stock from the table, given the primary key.

I have initialized some prepared statements. This is the one I’m using here:

stmtFindColumn = Database.getConnection().prepareStatement(String.format("select ? from %s where %s = ?",
            INVENTORY_TABLE_NAME, SKU) );

Now a separate method is called. I pass it a static const QTY_IN_STOCK, which is defined as “quantity_in_stock” and the item’s SKU number, which is the primary key in the table.

private int getIntegerFromTable(String column, String key) {

    int toReturn = 0;

    try {
        // Complete the prepared statement 
        stmtFindColumn.setString(1, column);
        stmtFindColumn.setString(2, key);

        ResultSet result = stmtFindColumn.executeQuery();               
        toReturn = result.getInt(column);

    } catch (SQLException e) {
        LOG.error(e.getMessage());
        e.printStackTrace();
    }
    return toReturn;
}

When I run the query I get an sql exception that tells me: Invalid column name quantity_in_stock.

I have tried using a while loop processing result.next() and get the same error. I can’t find any examples of how to properly get the results when you know only a single record is being returned.

Help!

EDIT: OK, I’ve found that part of my problem is I’m not getting a result set, where I should expect one. Any ideas?

UPDATE: I’ve tested my code, using a garden variety statement and a plain string query instead and it works just fine. So the problem is in my use of the prepared statement. Can someone check if I’m using the ? wildcards correctly? Thanks!

  • 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-27T05:05:36+00:00Added an answer on May 27, 2026 at 5:05 am

    DarkSquirrel42 is right — you can’t replace the column list of the select using a ? parameter marker. Instead, you can String.format that into place too, for example.

    bad:

    *select ? from INVENTORY_TABLE_NAME where SKU = ?
    

    good:

    select QUANTITY_IN_STOCK from INVENTORY_TABLE_NAME where SKU = ?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.