SQLException:结果集开始之前

发布于 2024-09-19 13:17:34 字数 427 浏览 2 评论 0原文

   ResultSet rs;
   rs = this.orderedProduct.select(" sum(unitstoproduce) "," soNo = "+ soNo);

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

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

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

   java.sql.SQLException: Before start of result set
   ResultSet rs;
   rs = this.orderedProduct.select(" sum(unitstoproduce) "," soNo = "+ soNo);

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

When i try to execute the above query inside the java class i'm getting an exception as below.
Here the orderedProduct(orderedZnAlProduct) is the table

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

   java.sql.SQLException: Before start of result set

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉墨 2024-09-26 13:17:34

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

I don't see where your query is executed (like statement.executeQuery()) but, this kind of errors generally happens when your cursor is not well positioned. You need to call something likers.next() or rs.first() to move your cursor and then to get the result.

追星践月 2024-09-26 13:17:34

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

select count(*) TABLE_NAME

,但在检索值时我从未在任何其他场景中遇到过错误,因此我假设对于只有一行的查询,我们需要显式提及 rs.first() 它会像魅力一样发挥作用。

Even I encountered the same problem when I tried to execute

select count(*) TABLE_NAME

But I never encountered the error in any other scenarios when retrieving the values, So I assumed for the queries which have only one row we need to explicitly mention rs.first() and it 'll work like a charm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文