Versions Compared

Key

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

Assume that the scenario is to delete a record from the Employee table based on the Employee ID. A SQL map of the following format –is suitable for the delete operation:

Code Block
languagesql
<delete id="EMPLOYEE_DELETE_MYAPP" parameterClass ="java.util.HashMap">

...


DELETE EMPLOYEE WHERE EMP_ID = #EmployeeId#

...


</delete>


And the corresponding code would be like -

Code Block
languagejava
try {

...

 
DatabaseRequest dbRequest = new DatabaseRequest();

...

 
dbRequest.setDataAccessMapKey("EMPLOYEE");

...


dbRequest.setOperation(DatabaseConstants.DELETE)

...


dbRequest.setOperationExtension("MYAPP");

...


dbRequest.addFilter(empIdToDelete); //Add the Emp Id to delete as filter

...

 
DatabaseResult dbResult = dbRequest.execute(); //Execute the select.

...


Logger.debug(" # rows deleted = " + dbResult.getNumberOfRowsAffected(); //Get the count of affected rows

...


} catch (DatabaseException dbException) {

...


//Handle the exception appropriately.

...


}