Bug #23337 | get java.sql.SQLException: Before start of result set | ||
---|---|---|---|
Submitted: | 16 Oct 2006 15:00 | Modified: | 16 Oct 2006 17:16 |
Reporter: | Sasi Levi | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / J | Severity: | S1 (Critical) |
Version: | OS: | ||
Assigned to: | CPU Architecture: | Any |
[16 Oct 2006 15:00]
Sasi Levi
[16 Oct 2006 15:22]
Mark Matthews
Executing a statement closes any open result sets that statement has created. Since you're re-executing the statement in your while{}, this code can not work.
[16 Oct 2006 17:16]
Sasi Levi
You right I didn't paste the right code, my fault , if (rs.last()) { maxId = rs.getInt(1); } The first code was pstmt.executeQuery().getInt(1) and on that was the error.
[16 Oct 2006 17:24]
Mark Matthews
You can't do "pstmt.executeQuery().getInt(1)" either. In JDBC newly-created result sets have their "cursor" positioned before the start of the result set. You can' call any get*() methods until you navigate into the result set somehow (e.g. first(), last(), next(), absolute(), relative(), etc. and check the result, to make sure you're on a valid row).