2
 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 
1

2 Answers 2

11

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

Dafuuu... SQL/JDBC can truly be a pain sometimes >< just spent two hours of debugging til finding this thread...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.