Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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
languagesql
<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:

Code Block
languagejava
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.

...


}