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:
Code Block |
---|
|
<update id="EMPLOYEE_UPDATE_MYAPP" parameterClass ="java.util.HashMap"> |
...
...
SET EMP_NAME = #EmployeeName#, MOB_NO = #mobileNum# |
...
WHERE EMP_ID = #EmployeeId# |
...
And the corresponding code for executing this update would be –as follows:
Code Block |
---|
|
List<Map> allEmployees = null; |
...
HashMap empDataToUpdate = getEmpDataToUpdate(); |
...
...
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. |
...