我想在我的数据库获取某个表中的列,但我得到了以下错误:错误在MySQL表中发现一列
值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) 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) 在webServices.TheServicesImplementation.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控制台成功)存在。任何人都可以帮我吗?
您是否尝试从mysql控制台执行此查询? – kosa
是的,它成功了......:/ – Marievi
您确定连接设置中的模式定义是正确的吗?你能否从同一张桌子获得另一列? – kosa