delete, 한 건 select
1) RoleDaoSqls 클래스 수정
public static final String SELECT_BY_ROLE_ID = "SELECT role_id, description FROM role where role_id = :roleId";
public static final String DELETE_BY_ROLE_ID = "DELETE FROM role WHERE role_id = :roleId";
2) RoleDao 클래스 수정
public int deleteById(Integer id) {
Map<String, ?> params = Collections.singletonMap("roleId", id);
return jdbc.update(DELETE_BY_ROLE_ID, params);
}
public Role selectById(Integer id) {
try {
Map<String, ?> params = Collections.singletonMap("roleId", id);
return jdbc.queryForObject(SELECT_BY_ROLE_ID, params, rowMapper);
}catch(EmptyResultDataAccessException e) {
return null;
}
3) JDBCTest 클래스 수정
int id = 201;
Role resultRole = roleDao.selectById(id);
System.out.println(resultRole);
int delete_count = roleDao.deleteById(id);
System.out.println(delete_count + "건 삭제: "+ id);