title: Retrieve the returned value from sql server stored procedure using java
body: <p>Here is my store procedure that returns a value. I need to call this procedure and get that return value into my java program.
  <code></p>
  
  <pre><code>CREATE PROCEDURE my_procedure @advisor de , @adv_xml xml   
  
  AS      
  
  
  begin        
    declare 
      @psrg_idi idi,
      @adv_cd cd,
      @CurrDate cdt
  
    set @adv_cd = (select adv_cd from dbo.ADVICE_LK where upper(rtrim(adv_de)) = upper(@advisor))
    set @psrg_idi = 0    
    set @CurrDate = getdate()
  
      BEGIN TRY     
        exec my_proc_2 @CurrDate,@psrg_idi output
  
        insert into
            ADVICE
            (psrg_idi,
             adv_cd,
             psra_original_xml)  
        values
          (@psrg_idi,
           @adv_cd,
           @adv_xml)  
  
        select 
          @psrg_idi as psrg_idi
  
      END TRY     
      BEGIN CATCH    
         DECLARE @ErrorMessage NVARCHAR(4000);    
         DECLARE @ErrorSeverity INT;    
         DECLARE @ErrorState INT;     
         SELECT     
           @ErrorMessage = ERROR_MESSAGE(),    
      @ErrorSeverity = ERROR_SEVERITY(),    
      @ErrorState = ERROR_STATE();    
     -- Use RAISERROR inside the CATCH block to return error    
     -- information about the original error that caused    
     -- execution to jump to the CATCH block.    
     RAISERROR (@ErrorMessage, -- Message text.    
       @ErrorSeverity, -- Severity.    
       @ErrorState -- State.    
       );    
     return -1    
       END CATCH    
  
  end
  </code></pre>
  
  <p></code></p>
  
  <p>Here is how I am trying to get this value into my java program returned by the above stored procedure. When I call this procedure from java, all the expected values are stored into database tables. But I am receiving the returned value groupId as '0'.. any idea or help will be highly appreciated. </p>
  
  <p><code></p>
  
  <pre><code>CallableStatement cs = con.prepareCall("{? = call my_procedure (?,?)}");                
  int i = 0;
  cs.registerOutParameter(++i, java.sql.Types.INTEGER);
  cs.setString(++i, advisor);
  cs.setString(++i, adviceXml);
  
  cs.execute();
  int groupId = cs.getInt(1);
  </code></pre>
  
  <p></code></p>
  
  <p>I have already reviewed the accepted answer <a href="https://stackoverflow.com/a/1948518/674476">https://stackoverflow.com/a/1948518/674476</a> . I am also trying in the same way, but somehow not able to get returned value </p>