0% found this document useful (0 votes)
71 views3 pages

Callable Statement

CallableStatement is a Java class that allows executing stored procedures in OAF applications. The example code shows how to: 1. Get an OADBTransaction object and use it to create an OracleCallableStatement for executing a stored procedure 2. Set the input parameter and register the output parameter type 3. Execute the callable statement and retrieve the output parameter value 4. Handle any SQLExceptions that may occur The stored procedure "xxtestproc" takes an employee number as input and returns the salary as output. The OAF controller code calls this procedure by passing the employee number from the page, and displays the returned salary.

Uploaded by

kishan reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views3 pages

Callable Statement

CallableStatement is a Java class that allows executing stored procedures in OAF applications. The example code shows how to: 1. Get an OADBTransaction object and use it to create an OracleCallableStatement for executing a stored procedure 2. Set the input parameter and register the output parameter type 3. Execute the callable statement and retrieve the output parameter value 4. Handle any SQLExceptions that may occur The stored procedure "xxtestproc" takes an employee number as input and returns the salary as output. The OAF controller code calls this procedure by passing the employee number from the page, and displays the returned salary.

Uploaded by

kishan reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Callable Statement:

We can use this for executing procedures in OAF application

CallableStatment is a java class provided by java for executing procedures

Example Code:

OADBTransaction oadbtransaction=oa.getOADBTransaction();

OracleCallableStatement oraclecallablestatement ;
String sql = "BEGIN proc_name (:1, :2); END;";
oraclecallablestatement = (OracleCallableStatement)
oadbtransaction.createCallableStatement(sql, -1);
try {
oraclecallablestatement.setInt(1, asg_id);
oraclecallablestatement.registerOutParameter(2,OracleTypes.VARCHAR,0);
oraclecallablestatement.execute();
outvar = oraclecallablestatement.getString(2);
oraclecallablestatement.close();
}
catch(SQLException exception){
outvar = "N";
}

Step1: Create a simple page with one text box and one button, set a new controller on the page

Empno:

Id: empno, DataType: NUMBER, Max Lenght: 4, Prompt: Enter Emp Num
Go Button:

Id: gobtn, prompt: GO

Step2: Write the procedure as per requirement.

create or replace procedure xxtestproc(p_emp_no in number,p_emp_sal out number)


is
v_sal number(10);
begin
select sal into v_sal from emp where empno=p_emp_no;
p_emp_sal:=v_sal;
end;

Step3: Code in processFormRequest to handle go button and execute procedure.

I mports:

// TO handle Exceptions of SQLs

import java.sql.SQLException;

// For providing Transaction Context

import oracle.apps.fnd.framework.server.OADBTransaction;

//Callable Statement

import oracle.jdbc.OracleCallableStatement;

//Data Type to work with callable statement

import oracle.jdbc.OracleTypes;

Code in PFR: after super line

// Getting value from the page and type casting to NUMBER


String empno=pageContext.getParameter("empno");
String empsalary=null;
// Check the GO button click
if(pageContext.getParameter("gobtn")!=null)
{
OADBTransaction
oadbtransaction=pageContext.getApplicationModule(webBean).getOADBTransaction();
// Creating object of OracleCallableStatement
OracleCallableStatement oraclecallablestatement;
// Build SQL statement
String sql = "BEGIN xxtestproc(:1, :2); END;";
// With the help of oadbtransaction, we are creating callable statement sql
oraclecallablestatement =
(OracleCallableStatement)oadbtransaction.createCallableStatement(sql, -1);
// Keep the execute() statement in try catch block
try {
// Set the in parameter
oraclecallablestatement.setString(1, empno);
// Register the out parameter is number
oraclecallablestatement.registerOutParameter(2,OracleTypes.VARCHAR,0);
oraclecallablestatement.execute();
empsalary = oraclecallablestatement.getString(2);
oraclecallablestatement.close();
}
catch(SQLException exception){
empsalary=null;
}
throw new OAException ("Salary is :"+empsalary, OAException.INFORMATION);
}

You might also like