aspose file tools*
The moose likes JDBC and the fly likes Problem : accessing record from a cursor returned from postgresql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply locked New topic
Author

Problem : accessing record from a cursor returned from postgresql

Kumar
Greenhorn

Joined: Aug 23, 2004
Posts: 6
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(1));
}
} //try
rs.close();
cst.close();
log("Records Retrieved Successfully");
} catch (SQLException sqle) {
log(sqle.getMessage());
log("Error while retrieving Records");
}

private void log(String mes){
System.out.println(mes);
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

"Kumar JC",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Snap! Do I win a prize?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

Kumar, not only do you need to change your display name, but please do not post the same question more than once, in either the same or in multiple forums.

Thanks for catching that Julian.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem : accessing record from a cursor returned from postgresql