title: Stored Procedure with return values
body: <p>I have a stored procedure "test", which looks like: </p>
  
  <pre><code>CREATE PROCEDURE test
  @name varchar(32)  
  AS
  DECLARE 
          @login_status  TINYINT, 
      @syb_login   varchar(20),
          @syb_pass   varchar(20)
  ...
  ..     
  
  
  BEGIN   
              SELECT @status = 0
              SELECT @login as login,
                     @pass as pass,
                     @status as status   
               RETURN 0 
          END
  </code></pre>
  
  <p>I need to pass a single input parameter "myName" as input parameter to this procedure and which in turn returns the login, pass and status as output (from only one record) parameters.</p>
  
  <p>In JDBC, I tried to do like below:</p>
  
  <pre><code> String query = "{call test(?,?,?)}";
      System.out.println(query);
      CallableStatement proc = null;
      ResultSet rs;
      try {
          proc = connection.prepareCall(query);
          proc.setString(1, "myName");
  
      proc.registerOutParameter(2, java.sql.Types.VARCHAR);
      proc.registerOutParameter(3, java.sql.Types.VARCHAR);
  
      proc.execute();
  
      System.out.println(proc.getString(2));
  </code></pre>
  
  <p>This always gives the exception:</p>
  
  <pre><code>java.sql.SQLException: JZ0SG: A CallableStatement did not return as many output parameters as the application had registered for it.
      at com.sybase.jdbc4.jdbc.SybConnection.getAllExceptions(Unknown Source)
      at com.sybase.jdbc4.jdbc.SybStatement.handleSQLE(Unknown Source)
      at com.sybase.jdbc4.jdbc.ParamManager.nextResult(Unknown Source)
      at com.sybase.jdbc4.jdbc.ParamManager.doGetOutValueAt(Unknown Source)
      at com.sybase.jdbc4.jdbc.ParamManager.getOutValueAt(Unknown Source)
      at com.sybase.jdbc4.jdbc.SybCallableStatement.getString(Unknown Source)
  </code></pre>
  
  <p>I tried with <a href="https://stackoverflow.com/questions/14834544/jdbc-execute-sql-server-stored-procedure-with-return-value-and-input-output-para">JDBC execute SQL Server stored procedure with return value and input/output parameters</a>,
  <a href="https://msdn.microsoft.com/en-us/library/ms378108.aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/ms378108.aspx</a> but this didn't work.</p>