Today I'm going to explain two methods for creating a new row.
1. createRow
public String myOwnCreateInsert_Person (int pid, String pname)
{
ViewObjectImpl vo = this.getPersonsUpdatable1();
try {
Row r = vo.createRow();
r.setAttribute("PersonId", pid);
r.setAttribute("PersonName", pname);
vo.insertRow(r);
}
catch (oracle.jbo.TooManyObjectsException tmoe) {
return "error";
}
this.getDBTransaction().commit();
return "success";
}
2. createAndInitRow
public String myOwnCreateInsert_Person (int pid, String pname)
{
ViewObjectImpl vo = this.getPersonsUpdatable1();
try {
NameValuePairs nvp = new NameValuePairs();
nvp.setAttribute("PersonId", pid);
nvp.setAttribute("PersonName", pname);
vo.insertRow(vo.createAndInitRow(nvp));
}
catch (oracle.jbo.TooManyObjectsException tmoe) {
return "error";
}
this.getDBTransaction().commit();
return "success";
}
---
Not to mention the second one is my favourite ; but it's doing the exact same thing. Why ? Check here.
Also, if you insert the new row in a table that contains a foreign key column, you should add this :
catch (oracle.jbo.DMLConstraintException dmle) {
return "error";
}
1 commentaire:
The link you mention is invalid URL :)
Enregistrer un commentaire