Are you sure that something somewhere (your connection pool, for example) isn't executing
another query on the given statement? _Something_ is closing that result set, either it's
explicitly closed, or it's being closed by the fact that the statement has either had
another query executed on it, or the statement itself has been closed, either explicitly
or by the Connection that created it being closed.
See everytime you execute the statement, all open resultsets will be closed. There is no way around that.
So, you will have to read the entire resultset and save the results, then loop through those results, setting of the query again for the "next level down/up" and, once again, reading in the entire result set etc.
Else, you need to create a new statement object instead of PrepareStatement.