I am calling an 2005 MS SQL Server stored procedure using the MS JDBC Driver and want to access the output parameters before processing the result set as follows:
proc = "{call mySproc(?,?,?)}";
conn = ds.getConnection();
callableStmt = conn.prepareCall(proc);
callableStmt.setString(1,inputParam);
callableStmt.registerOutParameter(2,Types.INTEGER);
callableStmt.registerOutParameter(3,Types.INTEGER);
callableStmt.execute();
rs = (ResultSet)callableStmt.getResultSet();
output[0] = callableStmt.getInt(2); //@rc
output[1] = callableStmt.getInt(3); //@rs
if(output[0] != 0){
//do some stuff
} else {
// process result set
}
Problem is that accessing the output parameters before processing the result set causes the result set to be closed.
Is there a way I can achive this without altering the stored procedure?
It's possible to do this via JDBC for other databases. However, from researching I found the JDBC Spec states:
For maximum portability, a call's ResultSet objects and update counts should be processed prior to getting the values of output parameters.
Is it the case that the MS JDBC Driver has been implemented to the letter of the law and other JDBC drivers have provided more flexible implementations?
Hoping someone can clear up my understanding on this issue.