Saturday, November 21, 2009

11G : Insert the row into ADF table using Store Procedure.


public String insert() throws SQLException{
// Add event code here...
System.out.println("Insert()...");
System.out.println("empid..."+empid);
System.out.println("startdate..."+startdate);
System.out.println("enddate..."+enddate);
System.out.println("jobid..."+jobid);
System.out.println("deptid..."+deptid);
System.out.println("::::::::::::::");
String procedure="{ call ADD_JOB_HISTORY(?,?,?,?,?) }";
CallableStatement cs=null;
Connection conn=null;
ResultSet rs=null;
try {
conn = DBConnectionClass.getConnection();
cs = conn.prepareCall(procedure);
cs.setString(1, empid); //IN
cs.setDate(2, startdate); //IN
cs.setDate(3, enddate); //IN
cs.setString(4, jobid); //IN
cs.setString(5, deptid); //IN
cs.execute();
rs = cs.getResultSet();
} catch (SQLException e) {
System.out.println("Inside Catch-Exception- "+e);
} finally {
System.out.println("Inside Finally");
cs.close();
}
return "success";
}


Store Procedure
-------------------
create or replace
PROCEDURE add_job_history
( p_emp_id job_history.employee_id%type
, p_start_date job_history.start_date%type
, p_end_date job_history.end_date%type
, p_job_id job_history.job_id%type
, p_department_id job_history.department_id%type
)
IS
BEGIN
INSERT INTO job_history (employee_id, start_date, end_date,
job_id, department_id)
VALUES(p_emp_id, p_start_date, p_end_date, p_job_id, p_department_id);
END add_job_history;


-----------------------
      public String getFirstName(){
           Connection con = null;
           Statement stmt = null;
           ResultSet rs = null;
           String FirstName = null;
           try {
               con = ConnectionClass.getConnection();
               stmt = con.createStatement();
               String query = "Select first_name from employees where empId = '101'";
               rs = stmt.executeQuery(query);
               while(rs.next()){
                   FirstName = rs.getString("first_name");
               }
           }
           catch(Exception e){
               e.printStackTrace();
           }
           finally{
               ConnectionClass.close(rs,stmt,con);
           }
           return corpBr;
       }