File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes DB2 stored proc returning a results set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "DB2 stored proc returning a results set" Watch "DB2 stored proc returning a results set" New topic

DB2 stored proc returning a results set

Richard Olmstead

Joined: Jun 12, 2006
Posts: 5
I'd like to return a results set from a DB2 stored proc, and have tried this:

String sql = " {call G714.GDDPOHP2(? , ?) } " ;
CallableStatement callable = conn.prepareCall( sql );

callable.setString(1, "76021592220080101");

(...both parms are defined to DB2 as INOUT ...)
callable.registerOutParameter(1, java.sql.Types.CHAR);
callable.registerOutParameter(2, java.sql.Types.CHAR);

What makes it tricky is, the stored procedure's cursor is defined WITH RETURN, and parameter #2 isn't the result set, but error messages sent back.
I'll execute, this way,


and have an error, here:
ResultSet rs = (ResultSet)callable.getObject(1);

I'd like to have the data available, like so:
while ( {
rs.getString(1) + "\t" +
rs.getString(2) + "\t" +
rs.getString(3) ) ;
Would anyone know how to receive the result-set data?

I agree. Here's the link:
subject: DB2 stored proc returning a results set
It's not a secret anymore!