Reputation: 5011
I am trying to get a column from a table in my database, but I get the following error :
java.sql.SQLException: Column 'price' not found. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870) at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1064) at com.mysql.jdbc.ResultSetImpl.getDouble(ResultSetImpl.java:2234) at webServices.TheServicesImplementation.findShops(TheServicesImplementation.java:964) at main.MainFunction.main(MainFunction.java:26)
The query I use is :
private final String priceSQL = "select price as price from items_shops i where i.shop_id = ? and i.item_id = ?";
and my code is :
try {
preparedStatementB = dbConnection.prepareStatement(priceSQL);
preparedStatementB.setInt(1, shop_id);
preparedStatementB.setInt(2, item_id);
setB = preparedStatementB.executeQuery();
if (!setB.next()) {
System.out.println("Error finding price.");
return null;
}
else
{
price = set.getDouble("price");
}
}catch (SQLException e) {
e.printStackTrace();
}finally{
try {
preparedStatementB.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
But this is weird, as a column price
does exist in the table items_shops
(executing the query in the SQL console succeeds). Could anyone help me?
Upvotes: 0
Views: 510
Reputation: 6018
The resultset is assigned to a variable called setB
but you're trying to extract the price from a variable called set
.
Upvotes: 3