Java Exhausted Result Set / Oracle & Websphere 5.1|java.sql.SQLException: Exhausted Resultset

I am experiencing some problems with a simple query on a thin oracle driver. I am using a connection from the application server connection pool on a cluster machine. Basically this is my code:

try {
conn = DAOFactory.getConnection();
stmt = conn.prepareStatement(SELECT_STATEMENT);
stmt.setInt(1, var);
stmt.setFetchSize(max);
rs = stmt.executeQuery();

while( rs.next() ) {
long id = rs.getLong(1);
}

All this I incorporate into a try/catch block like this:

} catch(SQLException e) {
// some exception handling
} finally {
try {
if(stmt!=null)
stmt.close();
if(rs!=null)
rs.close();
if(conn!=null)
conn.close();
} catch (SQLException e1) {
// some exception handling
}
}

After some runs I get sporadically the “Exhausted Resultset” Exception at line rs.getLong(1). This indicates, that my result set is closed. This will imply that rs.next() returns true even if there are no results! This kind of strange behaviour I have already noticed by some other users.

My question: How can I ensure that rs.next() will return false if the result set is empty? Does anybody else encounter this problem before and have a smooth solution?

No comments:

Post a Comment

Please Provide your feedback here