Wednesday, 10 October 2012

How to Show values on OA Page by directly using Connection and Select Statment and ResultSet Object Example

package oracle.apps.ak.TravelRequestTesting.webui;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;
import java.sql.*;
/**
 * Controller for ...
 */
public class MyCOTR extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
  /**
   * Layout and page setup logic for a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
   

  }
  /**
   * Procedure to handle form submissions for form elements in
   * a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    String  ename= null;
    String  edepartment= null;
    String  esalary=null;
   if(pageContext.getParameter("ShowRecord")!=null){
  //pempno is  passed to where clause for the query to get that employee in db
  //user enter the pempno on the page first than it is passed
   OAMessageTextInputBean  tibempno = (OAMessageTextInputBean)webBean.findIndexedChildRecursive("empno");
   String pempno=(String)tibempno.getValue(pageContext);
try{
  OAApplicationModule am=pageContext.getApplicationModule(webBean);
  Connection conn =am.getOADBTransaction().getJdbcConnection();
  Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery("select * from EmployeeTest where eno="+pempno+" ");
// recordset  rs is populated by the above query pick the record one by one
 if ( rs.next() )
        {
        //values of rs is stored in string variables such as ename,esalary
        ename = rs.getString("ename");
        edepartment=rs.getString("edepartment");
        esalary = rs.getString("esalary");
        }
        rs.close();
       stmt.close();
}catch(Exception e){System.out.println(e.toString());}

 //now the MessageTextInputBean is set   on the page
      OAMessageTextInputBean  tibename = (OAMessageTextInputBean)webBean.findIndexedChildRecursive("ename");
      tibename.setValue(pageContext,ename);
       
      OAMessageTextInputBean  tibedepartment = (OAMessageTextInputBean)webBean.findIndexedChildRecursive("edepartment");
      tibedepartment.setValue(pageContext,edepartment);
      OAMessageTextInputBean  tibesalary = (OAMessageTextInputBean)webBean.findIndexedChildRecursive("esalary");
      tibesalary.setValue(pageContext,esalary);
    
 
  
  }
}
}

No comments:

Post a Comment