SQLException:结果集开始之前
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看不到您的查询在哪里执行(如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 like
rs.next()
orrs.first()
to move your cursor and then to get the result.即使我在尝试执行时遇到了同样的问题
,但在检索值时我从未在任何其他场景中遇到过错误,因此我假设对于只有一行的查询,我们需要显式提及 rs.first() 它会像魅力一样发挥作用。
Even I encountered the same problem when I tried to execute
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.