title: Accessing output parameters before processing result set in SQL Server via jdbc
body: <p>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:</p>
  
  <pre><code>        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
          }  
  </code></pre>
  
  <p>Problem is that accessing the output parameters before processing the result set causes the result set to be closed.    </p>
  
  <p>Is there a way I can achive this without altering the stored procedure?</p>
  
  <p>It's possible to do this via JDBC for other databases. However, from researching I found the <a href="http://java.sun.com/javase/6/docs/api/java/sql/CallableStatement.html" rel="nofollow noreferrer">JDBC Spec</a> states:</p>
  
  <blockquote>
    <p>For maximum portability, a call's
    ResultSet objects and update counts
    should be processed prior to getting
    the values of output parameters.</p>
  </blockquote>
  
  <p>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? </p>
  
  <p>Hoping someone can clear up my understanding on this issue.</p>