Wednesday, 17 August 2016

CODE TO CALL "OUT" PARAMETERS FROM PLSQL PROCEDURES AND GET THEM IN BACKING BEAN IN ADF



CODE TO CALL 'OUT' PARAMETERS FROM  PLSQL PROCEDURES AND GET THEM IN BACKING BEAN IN ADF:

The Code is tested on ADF 11.1.2.4.0 version.

Sometimes we have one or more return results as per our requirement.To fulfil this requirement we make use of procedures with "OUT" parameters , as function gives us only one return result.

Here the below code explains us the process of implementing pl-sql procedures in ADF.

1) Code to call procedure in adf:


Step 1: Create a procedure 'GET_INVRESPONSEKEY_USERNM'  in package named 'adf_pkg'  in  database which gives two out parameters and has one in parameter.
 
Step 2:  Add the code in App Module which calls the procedure.


 
public String[] GET_INVRESPONSEKEY_USERNM(int USERID)
{

       

       CallableStatement st1 = null;

      

               try {


st1 =    getDBTransaction().createCallableStatement("begin adf_pkg.GET_INVRESPONSEKEY_USERNM(?,?,?); end;",0);

     

          st1.setInt(1,USERID);

          st1.registerOutParameter(2,Types.VARCHAR);

          st1.registerOutParameter(3,Types.VARCHAR);

          st1.executeUpdate();

                     

           String      RESPONSIBILITY_KEY = st1.getString(2);

           String        USER_NAME = st1.getString(3);

                     

System.out.println("RESPONSIBILITY_KEY=" + RESPONSIBILITY_KEY);

System.out.println("USER_NAME=" + USER_NAME);

                     

return new String[] {RESPONSIBILITY_KEY,USER_NAME} ;

                     

                        
catch (SQLException e) 
  {       

                  throw new JboException(e);    

      }
}



Step 3 : Drag and drop the function name by editing Client Interface.
 

Step  4 : To get the 'Out' parameters in backing bean of jsf page add the below code. 

BindingContainer bindings = getBindings();

OperationBinding operationBinding =bindings.getOperationBinding("GET_INVRESPONSEKEY_USERNM");

Object result = operationBinding.execute();

Object ReturnValue[] = (Object[])operationBinding.getResult();

         
String RESPONSIBILITY_KEY = (String)ReturnValue[0];

System.out.println("RESPONSIBILITY_KEY=" + RESPONSIBILITY_KEY);

      
String USER_NAME  = (String)ReturnValue[1];

System.out.println("USER_NAME=" + USER_NAME);