In this post we will take a look at java.sql.SQLException :Exhausted Resultset in JDBC java. And we will try to figure out why it happen and find appropriate solution to solve it.
You must Read :Sqlexception-in-java
java.sql.SQLException: Exhausted Resultset
It is thrown when cursor does not point to any row in ResultSet’s object in JDBC java.
java.sql.SQLException: Exhausted Resultset
It is thrown when cursor does not point point to any row in ResultSet’s object in JDBC java.
is thrown when rs.getString("COLUMN_NAME") is called before calling rs.next() on ResultSet object.
rs = prepStmt.executeQuery();
//At this point cursor is before the first position of ResultSet object
System.out.println(rs.getString("COLUMN_NAME"));//java.sql.SQLException: Exhausted Resultset
java.sql.SQLException: Exhausted Resultset
It is thrown when cursor does not point to any row in ResultSet’s object.
It may be thrown when rs.getString("COLUMN_NAME") is called after iterating on ResultSet object.
rs = prepStmt.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("COLUMN_NAME"));
}
//At this point cursor is after the last position of ResultSet object
System.out.println(rs.getString("COLUMN_NAME"));//java.sql.SQLException: Exhausted Resultset
java.sql.SQLException: Exhausted Resultset
It is thrown when cursor does not point to any row in ResultSet’s object.
It may be thrown when rs.next() is called after closing the ResultSet object.
rs = prepStmt.executeQuery();
rs.close();
rs.next(); //java.sql.SQLException: Exhausted Resultset