views:

222

answers:

1

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.

+1  A: 

The output parameters come on the wire after all result set. Any client, regardless of the platform or technology, has to first parse all results before they can even see the output parameters values.

If there are clients that offer the value of output parameters before consuming the result sets it means they cache the result sets in memory. Very bad considering result sets can grow quote large.

Remus Rusanu