This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC 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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "DB2 stored proc returning a results set" Watch "DB2 stored proc returning a results set" New topic
Author

DB2 stored proc returning a results set

Richard Olmstead
Greenhorn

Joined: Jun 12, 2006
Posts: 5
Hello,
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,

callable.execute();

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

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

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DB2 stored proc returning a results set