title: How to get OUTPUT parameter of stored procedure sp_setapprole in SQLServer
body: <p>I'm using the following JDBC driver (the one from Microsoft): <a href="http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx</a>.</p>
  
  <p>I want to retrieve the OUTPUT parameter (@cookie) of the stored procedure <code>sp_setapprole</code>. I can call the procedure fine like this, but I can't figure out how to retrieve the OUTPUT parameter.</p>
  
  <pre><code>statement = connection.createStatement();
  statement.execute("EXEC sp_setapprole '" + applicationRoleName + "', '" + applicationRolePassword + "'");
  </code></pre>
  
  <p>I tried with a PreparedStatement and a CallableStatement and I always get the following exception: <code>Stored procedure 'sys.sp_setapprole' can only be executed at the ad hoc level.</code>. I found this post: <a href="https://stackoverflow.com/a/6944693/1362049">https://stackoverflow.com/a/6944693/1362049</a>, but I don't like the solution (use another JDBC driver).</p>
  
  <p>So my question: how to get OUTPUT parameter from stored procedure <code>sp_setapprole</code> in SQLServer using a <code>Statement</code>.</p>