title: How to call SQL Server stored procedure in java with result set, and input, output parameters?
body: <p>In Oracle, I can use the following:</p>
  
  <pre><code>    String query = "{ ? = call get_config_func( ?, ? ) }";
      try
      {
          CallableStatement cs = con.prepareCall( query );
          cs.registerOutParameter(1, OracleTypes.CURSOR);
          cs.setInt( 2, i );
          cs.registerOutParameter(3, java.sql.types.INTEGER);
          cs.execute();
          ResultSet results = ((OracleCallableStatement)cs).getCursor (1);
          String val = cs.getString(3);
  
          if( results != null)
          {
              while( results.next() )
              {
               .....
  </code></pre>
  
  <p>However I am stuck with the reference to Oracle that won't work with SQL Server.</p>
  
  <p>I tried the following:</p>
  
  <pre><code>    String query = "{ call uspGetLastLocation( ?, ? }";
      try
      {
          cs = con.prepareCall( query );
          cs.setLong(1, id );
          cs.registerOutParameter(2, java.sql.Types.VARCHAR );
          rs = cs.executeQuery();
  
          while(rs.next())
          {
              .....
  </code></pre>
  
  <p>But I get the following error </p>
  
  <blockquote>
    <p>Incorrect syntax near '{'.</p>
  </blockquote>
  
  <p>I've seen examples using <code>PreparedStatement</code> instead of <code>CallableStatement</code> and change the query to</p>
  
  <pre><code>    String query = "EXEC uspGetLastLocation  ?, ?";
  </code></pre>
  
  <p>But I can't figure out how to handle the Output parameter.</p>
  
  <p>Any suggestions or pointer to a reference?</p>
  
  <p>Thanks.</p>