【问题标题】:SQLException : Before start of result setSQLException : 结果集开始之前
【发布时间】:2011-04-12 13:33:07
【问题描述】:
   ResultSet rs;
   rs = this.orderedProduct.select(" sum(unitstoproduce) "," soNo = "+ soNo);

   int sum = Integer.parseInt(rs.getString(1));

当我尝试在 java 类中执行上述查询时,我得到一个 exception,如下所示。 这里的orderedProduct(orderedZnAlProduct) 是表格

   SELECT  sum(unitstoproduce)  FROM orderedZnAlProduct WHERE  soNo = '15005'

   java.sql.SQLException: Before start of result set

【问题讨论】:

标签: java mysql jdbc resultset sqlexception


【解决方案1】:

我看不到您的查询在哪里执行(例如 statement.executeQuery()),但是这种错误通常发生在您的光标位置不正确时。您需要调用类似rs.next()rs.first() 来移动光标然后获取结果。

【讨论】:

    【解决方案2】:

    即使我尝试执行时也遇到了同样的问题

    select count(*) TABLE_NAME
    

    但在检索值时,我从未在任何其他情况下遇到过错误,因此我假设对于只有一行的查询,我们需要明确提及 rs.first(),它会像魅力一样工作。

    【讨论】:

    • Dafuuu... SQL/JDBC 有时真的很痛苦>
    猜你喜欢
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 2016-07-15
    • 2011-01-08
    • 2023-04-11
    • 2013-10-01
    相关资源
    最近更新 更多