title: JDBC execute SQL Server stored procedure with return value and input/output parameters
body: <p>I have a stored procedure that takes 1 input value, 2 output parameters and also returns a value on execution</p>
  
  <p>Over the internet i saw references using Call</p>
  
  <pre><code>CallableStatement cstmt = conn.prepareCall("{call ? = spName(?, ?, ?)}");
  cstmt.registerOutParameter(1, Types.INTEGER);
  cstmt.setObject(2, Types.INTEGER);
  cstmt.registerOutParameter(3, Types.NVARCHAR);
  cstmt.registerOutParameter(4, Types.NVARCHAR);
  </code></pre>
  
  <p>But this gives me the error </p>
  
  <pre><code>"Incorrect syntax near '{'"
  </code></pre>
  
  <p>Then i decided to do like the SQL Management Studio generated SQL code:</p>
  
  <pre><code>CallableStatement cstmt = conn.prepareCall("exec ? = spName ?, ?, ?");
  cstmt.registerOutParameter(1, Types.INTEGER);
  cstmt.setObject(2, Types.INTEGER);
  cstmt.registerOutParameter(3, Types.NVARCHAR);
  cstmt.registerOutParameter(4, Types.NVARCHAR);
  </code></pre>
  
  <p>But this gives me the error </p>
  
  <pre><code>"Incorrect syntax near '='"
  </code></pre>
  
  <p>I think this is because the query gets transformed to </p>
  
  <pre><code>"exec @P1 OUT = spName @P2, @P3 OUT, @P4 OUT" 
  </code></pre>
  
  <p>and it doesn't work either on SQL Management Studio because 'OUT' appers before '='</p>
  
  <p>And this leaves me without ideas because it doesn't work either way.</p>
  
  <p>Any suggestions?</p>
  
  <p>Thank you!</p>