Estou o obtendo o erro The result set is closed no código abaixo:
public List retornaCategorias() throws Exception {
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rset = null;
ResultSet rsImagem = null;
try {
String sb = null;
String comandoSQL = null;
sb = "select * from grupo where not (nome_grupo is null) order by nome_grupo desc ";
comandoSQL = "select count(*) as total from produto where cp_grupo = ? and ( not cp_imgprod is null)";
stmt = conn.createStatement();
pstmt = conn.prepareStatement(comandoSQL);
rset = stmt.executeQuery(sb);
List<Categoria> categorias = new ArrayList<Categoria>();
Categoria umaCategoria;
while (rset.next()) {
umaCategoria = new Categoria();
umaCategoria.setDescricao(rset.getString("nome_grupo"));
umaCategoria.setId(rset.getInt("cp_grupo"));
pstmt.setInt(1,umaCategoria.getId());
rsImagem = pstmt.executeQuery();
if (rsImagem.next()) {
if (rsImagem.getInt("total") > 0) {
categorias.add(umaCategoria);
}
}
}
return categorias;
} finally {
if (rset != null) try { rset.close(); } catch(Exception e) { }
if (stmt != null) try { stmt.close(); } catch(Exception e) { }
}
}
este erro acontece na segunda iteração do loop mais externo. precisamente na linha while () rset.next()
Nesse código, abro um resultset e com dados desse abro outro aninhadamente…
Parece que quando ele chega ao fim do resultset interno ele fecha o primeiro!
Será que eu teria que usar uma connection para cada resultset?
Alguem tem alguma idéia?
Hübner (ETI)