简体   繁体   中英

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

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() or rs.first() to move your cursor and then to get the result.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM