Book Image

SPRING COOKBOOK

Book Image

SPRING COOKBOOK

Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Deleting an object


In this recipe, we will add a DAO method to delete an existing row from the database.

How to do it…

Use an SQL delete query and execute it using the update() method:

public void delete(User user) {
  String sql = "delete from user where id=?";
  getJdbcTemplate().update(sql, user.getId());
}