Java Sample code (Company update() method)
public void updateElement(int index, Object obj) throws Exception {
//Check to see if obj ect parameter is not null
if (!(obj == null)){
try{
validation(obj);
// System.out.println("End Validation");
Company passedCompany = (Company)obj;
jobsdb.Company tableCompany = new jobsdb.Company();
tableCompany.setName(passedCompany.getName());
tableCompany.setContact(passedCompany.getContact());
//Date conversion
String date = passedCompany.getEnroll();
date = TextFields.DateText.convertDate(date);
//System.out.println(date);
tableCompany.setEnroll(java.sql.Date.valueOf(date));
//start convert phone format:
String phone = passedCompany.getPhone();
phone = TextFields.PhoneText.unformatPhone(phone);
//passedCompany.setPhone(TextFields.PhoneText.unformatPhone(phone));
tableCompany.setPhone(phone);
//end convert phone format:
passedCompany.getPhone()
tableCompany.setNotes(passedCompany.getNotes());
tableCompany.setId(passedCompany.getId());
tableCompany.update();
Company clone = new Company(passedCompany);
//we now delete and insert the 'new' edited
version:
getListOfCompanies().setElementAt(clone, index);
com.sun.java.swing.JOptionPane.showMessageDialog
(null, "You have successfully updated the " + clone.getName()
+ " information.");
}//end try
catch(ValidationException e){
}
catch(Exception e){
com.sun.java.swing.JOptionPane.showMessageDialog
(null, "The record was not updated. \n
Please re select the item and try again.");
}// end catch
}//end if
}//end method