我正在尝试从数据库中的表中获取列,但是我收到以下错误:
java.sql.SQLException:列'价格'未找到。 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870) 在com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1064) 在com.mysql.jdbc.ResultSetImpl.getDouble(ResultSetImpl.java:2234) 在webServices.ServicesImplementation.findShops(TheServicesImplementation.java:964) 在main.MainFunction.main(MainFunction.java:26)
我使用的查询是:
private final String priceSQL = "select price as price from items_shops i where i.shop_id = ? and i.item_id = ?";
我的代码是:
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();
}
}
但这很奇怪,因为列price
确实 存在于表items_shops
中(在SQL控制台中执行查询成功) 。有谁可以帮助我?
答案 0 :(得分:3)
结果集已分配给名为setB
的变量,但您尝试从名为set
的变量中提取价格。