【发布时间】:2014-01-25 11:46:51
【问题描述】:
我得到了这个错误:java.sql.SQLException: Illegal operation on empty result set.我不明白为什么,我用while循环进入最终搜索的行。
rs1=st1.executeQuery("select product.price,product.id from product,warehouse,shop
where product.brand ='"
+ Brand
+ "' and product.productType='"
+ Product
+ "'and shop.quantity + warehouse.quantity='"
+ Quantity
+ "' and product.id=shop.idProduct");
while (rs1.next()) {
price = rs.getInt("price");
idProduct = rs.getString("id");
countWareHouse++;
}
if (countWareHouse > 0) {
JOptionPane.showConfirmDialog(Sale,
"Do you want to add this " + Product
+ "int the cart?", "CART",
JOptionPane.OK_CANCEL_OPTION);
Prices.add(price);
}
}
【问题讨论】:
-
你能显示完整的代码吗?
-
您没有向我们展示罪魁祸首的代码。
while循环中有什么。并使用PreparedStatement构建查询。 -
Brand,Product, 和Quantity应该是避免sql注入攻击的参数。 -
您需要显示更多代码。您所拥有的不应导致此异常。
-
同时我只是增加一个计数变量。