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!