Update Operation

Let us take the scenario where the user is allowed a screen to update the details of an Employee based on their Employee Id. For this scenario, we need to define an update query in the SQL map as –follows:

<update id="EMPLOYEE_UPDATE_MYAPP" parameterClass ="java.util.HashMap">
UPDATE EMPLOYEE
SET EMP_NAME = #EmployeeName#, MOB_NO = #mobileNum#
WHERE EMP_ID = #EmployeeId#
</update>


And the corresponding code for executing this update would be –as follows:

List<Map> allEmployees = null;
HashMap empDataToUpdate = getEmpDataToUpdate();
try { 
DatabaseRequest dbRequest = new DatabaseRequest(); 
dbRequest.setDataAccessMapKey("EMPLOYEE");
dbRequest.setOperation(DatabaseConstants.UPDATE)
dbRequest.setOperationExtension("MYAPP");
dbRequest.addData(empDataToUpdate); //Set the complete data that needs to be updated 
dbRequest.execute(); //Execute the update.
} catch (DatabaseException dbException) {
//Handle the exception appropriately.
}