We have seen declarative approach to insert new row in database.
In this post i will explain you how to insert new row Programmatically.
1. Create the AppModuleImpl class and also create the java class for respective ViewObject. In this example i am working on EmployeeView. So i have generated EmploueeViewImpl java class.
2. Create the user defined method in AppModuleImple calss as shown below.
public void createNewRow(){
//get he EmployeeViewImpl class instance
EmployeesViewImpl vo=this.getEmployeesView1();
// Create new row to insert data
Row r=vo.createRow();
//Set the values to respective attributes.
r.setAttribute("EmployeeId", 509);
r.setAttribute("FirstName", "test");
r.setAttribute("LastName", "test");
r.setAttribute("Email", "test12@gmail.com");
r.setAttribute("PhoneNumber", "800000444");
r.setAttribute("HireDate", new Timestamp(System.currentTimeMillis()));
r.setAttribute("JobId", "IT_PROG");
r.setAttribute("Salary", 5000);
r.setAttribute("CommissionPct", "");
r.setAttribute("ManagerId", "");
r.setAttribute("DepartmentId", 340);
//insert row in the view object
vo.insertRow(r);
//commit the transaction
this.getDBTransaction().commit();
}
In this post i will explain you how to insert new row Programmatically.
1. Create the AppModuleImpl class and also create the java class for respective ViewObject. In this example i am working on EmployeeView. So i have generated EmploueeViewImpl java class.
2. Create the user defined method in AppModuleImple calss as shown below.
public void createNewRow(){
//get he EmployeeViewImpl class instance
EmployeesViewImpl vo=this.getEmployeesView1();
// Create new row to insert data
Row r=vo.createRow();
//Set the values to respective attributes.
r.setAttribute("EmployeeId", 509);
r.setAttribute("FirstName", "test");
r.setAttribute("LastName", "test");
r.setAttribute("Email", "test12@gmail.com");
r.setAttribute("PhoneNumber", "800000444");
r.setAttribute("HireDate", new Timestamp(System.currentTimeMillis()));
r.setAttribute("JobId", "IT_PROG");
r.setAttribute("Salary", 5000);
r.setAttribute("CommissionPct", "");
r.setAttribute("ManagerId", "");
r.setAttribute("DepartmentId", 340);
//insert row in the view object
vo.insertRow(r);
//commit the transaction
this.getDBTransaction().commit();
}





