resultset error
Hello,
I seem to have a problem with the following code. It throws the following exception at the while statement if there is more
than one row returned from the first query:
java.sql.SQLException: Operation not allowed after ResultSet closed
try{
result = statement.executeQuery(query1);
String fileDescrip ="";
String user1 ="";
String lastname ="";
ResultSet rs =null;//result set for username
while (result.next()){
fileDescrip = result.getString(1);
user1 = result.getString("added_by");
rs = statement.executeQuery(query2);
if(rs.next()){
lastname = rs.getString("lname");
}else{lastname ="Unkown";}
rs.close();
}
}catch (Exception tpex){
System.err.println("err viewing taskplan " + tpex);
}finally{
result.close();
statement.close();
connection.close();
}
[1687 byte] By [
maccarteea] at [2007-11-27 6:44:36]

# 2
java.sql.SQLException: Operation not allowed after ResultSet closed
The error message speaks for itself. If you close an resultset, then the action at the given line isn't allowed.
So, look where you're closing the resultset and ask yourself if it is the right place to close the resultset.
# 3
> Your resultset called rs has no data in it as far as
> I can see. If is equal to null.
> Did you mean to use result and not rs ?
The first query is to get userid and other data from one table. Then I need to lookup another table to find the user's last name using the userid from the first query.
I cannot use result for the second query, since the remaining rows of the orginal query will be overwritten with the new rows of the second query.
The code works fine for the first result row, but throws the exception when it makes it back to the while loop.
I know I could combine both queries, but I want to keep them separate for error checking (If userid has no entry in user table, result row will be null).
# 7
> This is just a nasty workaround.
>
> You're closing the resultset *inside* the while loop,
> which caused the resultset being inaccessible in the
> subsequent loops.
I commented out both close statements before I tried the new statement instance. Didn't work. Besides, I was closing the second result set, which only contained one row.