非法ResultSet

时间:2014-01-25 11:46:51

标签: java mysql syntax

我收到了这个错误: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);
                }
                }

1 个答案:

答案 0 :(得分:3)

在循环中,您使用rs代替rs1。如果这不是发出编译器错误,我假设rs在全局命名空间中,但在当前状态下为空。