【问题标题】:Illegal ResultSet非法结果集
【发布时间】: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注入攻击的参数。
  • 您需要显示更多代码。您所拥有的不应导致此异常。
  • 同时我只是增加一个计数变量。

标签: java mysql syntax


【解决方案1】:

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

【讨论】:

  • 建议:在 ResultSet 实例上使用文字名称,而不是“rs1”等。更好:productPriceResultSet e.a.为了防止。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-08
  • 2016-04-30
  • 1970-01-01
  • 2011-08-25
相关资源
最近更新 更多