Hi,
I have written a stored function in postgreSQL which returns a cursor and trying to access the records of the RecordSet using
jdbc callable statements. The result is that it is not displaying anything and the resultset seems to be empty. kindly please guide me as how to approach to achieve the said task. My code looks like this
stored function
---------------
CREATE or REPLACE FUNCTION doQuery(refcursor) RETURNS refcursor AS '
DECLARE
ref refcursor;
BEGIN
open $1 for select * from
test;
RETURN $1;
END;
' LANGUAGE plpgsql;
Client Application
------------------
private void listData() {
String cur_name="funccursor";
try {
CallableStatement cst = c.prepareCall("{?=call doQuery(?)}");
cst.registerOutParameter(1, Types.OTHER);
cst.setString(2,cur_name);
cst.execute();
rs = (ResultSet) cst.getObject(1);
while (rs.next()) {
log(rs.getString("name"));
}
} //try
rs.close();
cst.close();
log("Records Retrieved Successfully");
} catch (SQLException sqle) {
log(sqle.getMessage());
log("Error while retrieving Records");
}