Spring + JDBC를 이용하여 개발 시에 queryForObject 메서드를 사용하여 하나의 객체만 가져올 경우 해당 데이터가 없으면 org.springframework.dao.EmptyResultDataAccessException 예외가 발생하게 된다.
//특정 사용자가 참여한 크루전 찾기
public BattleDTO selectOneSearchMemberBattle(BattleDTO battleDTO){
System.out.println(" [로그] com.coma.app.biz.battle.selectOneSearchMemberBattle 시작");
BattleDTO result = null;
Object[] args = new Object[]{battleDTO.getBattle_crew_num()};
try {
result = jdbcTemplate.queryForObject(SEARCH_MEMBER_BATTLE, args, new BattleRowMapperOneSearchMemberBattle());
}catch(Exception e){
System.err.println(" [에러] com.coma.app.biz.battle.selectOneSearchMemberBattle Sql문 실패 : SEARCH_MEMBER_BATTLE = " + SEARCH_MEMBER_BATTLE);
e.printStackTrace();
}
return result;
}
JdbcTemplate.queryForObject 메서드가 예상한 결과가 1건이지만 실제로는 결과가 없어서 발생한 것이다.
사용자가 가입한 크루(보통 게임으로 따지면 길드 ?)가 없는 경우의 유효성검사를 체크하던 도중에 만났다.
쿼리문이 틀리지 않았어도, Sql문이 틀렸다는 에러문구가 뜰 수도 있다.,,
'에러일기' 카테고리의 다른 글
jakarta.el.PropertyNotFoundException (0) | 2024.11.07 |
---|---|
java.lang.NumberFormatException: For input string: "null" (0) | 2024.11.06 |
java.sql.SQLIntegrityConstraintViolationException (0) | 2024.10.28 |
java.nio.file.AccessDeniedException (1) | 2024.10.23 |
org.springframework.web.multipart.MultipartException (0) | 2024.10.21 |