title: Multiple result sets and return value handling while calling sql server stored procedure from Groovy
body: <p>I have MS SQL Server stored procedure (SQL Server 2012) which returns:</p>
  
  <ol>
  <li>return value describing procedure execution result in general (successfull or not) with <code>return @RetCode</code> statement (RetCode is int type)</li>
  <li>one result set (several records with 5 fields each)</li>
  <li>another result set (several records with 3 fields each) </li>
  </ol>
  
  <p>I calling this procedure from my Groovy (and Java) code using Java's CallableStatement object and I cannot find right way to handle all three outputs.</p>
  
  <p>My last attempt is</p>
  
  <pre><code>CallableStatement proc = connection.prepareCall("{ ? = call Procedure_Name($param_1, $param_2)}")
  proc.registerOutParameter(1, Types.INTEGER)
  boolean result = proc.execute()
  int returnValue = proc.getInt(1)
  println(returnValue)
  while(result){
      ResultSet rs = proc.getResultSet()
      println("rs")
      result = proc.getMoreResults()
  }
  </code></pre>
  
  <p>And now I get exception:</p>
  
  <pre><code>Output parameters have not yet been processed. Call getMoreResults()
  </code></pre>
  
  <p>I tried several approaches for some hours but didn't find correct one. Some others produced another exceptions. </p>
  
  <p>Could you please help me with the issue?</p>
  
  <p>Thanks In Advance!</p>
  
  <p><strong>Update</strong> (for Tim):
   I see rc while I launched code: </p>
  
  <pre><code> Connection connection = dbGetter().connection 
   CallableStatement proc = connection.prepareCall("{ ? = call Procedure_Name($param_1, $param_2)}") 
   boolean result = proc.execute() 
   while(result){ 
       ResultSet rs = proc.getResultSet() 
       println(rs) 
       result = proc.getMoreResults() 
   }
  </code></pre>
  
  <p>I see rc as object: <code>net.sourceforge.jtds.jdbc.JtdsResultSet@1937bc8</code></p>