postgresql con jdbc y procedimientos almacenados (funciones): ResultSet
Acabo de intentar llamar a una función almacenada desde el servidor (getStat), que se ve así:
create type stat as (type text, location text, number int);
create function getStat() returns setof stat as 'select distinct table1.type, table1.location, table1.number from table1, table2 where table2.finding=10 order by number desc;' language 'sql';
Ahora aquí está el código jdbc:
CallableStatement callable = null;
String storedProc = "{call getStat(?, ?, ?)}";
try {
callable = connection.prepareCall(storedProc);
callable.registerOutParameter(1, java.sql.Types.VARCHAR);
callable.registerOutParameter(2, java.sql.Types.VARCHAR);
callable.registerOutParameter(3, java.sql.Types.INTEGER);
boolean results = callable.execute();
System.out.println(callable.getString(1));
System.out.println(callable.getString(2));
System.out.println(callable.getInt(3));
while(results){
ResultSet rs = callable.getResultSet();
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getInt(3));
}
//rs.close();
results = callable.getMoreResults();
}
De acuerdo, y ahora el problema: cuando lo llamo, simplemente imprime la primera línea, de todo el volumen, que debe ser printend. Sí, eso está claro, porque ejecuto el siguiente código:
System.out.println(callable.getString(1));
System.out.println(callable.getString(2));
System.out.println(callable.getInt(3));
Pero hago lo mismo en el bucle while ... y no se muestra nada más.
Tal vez el problema sea algo obvio, pero me falta que :(
¡Gracias!