gpt4 book ai didi

java - 在 MySQL 表中查找列时出错

转载 作者:太空宇宙 更新时间:2023-11-03 11:45:35 24 4
gpt4 key购买 nike

我试图从我的数据库中的表中获取一列,但出现以下错误:

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)

我使用的查询是:

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 does 列存在于表 items_shops 中(执行查询在 SQL 控制台中成功)。谁能帮帮我?

最佳答案

结果集被分配给一个名为 setB 的变量,但您正试图从一个名为 set 的变量中提取价格。

关于java - 在 MySQL 表中查找列时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39082955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com