Skip to content

Conversation

@ZinYan
Copy link

@ZinYan ZinYan commented Nov 14, 2025

5단계 - 데이터베이스 적용하기
6단계 - 데이터 조회하기
7단계 - 데이터 추가/삭제하기

Copy link

@juanxiu juanxiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~!

keyHolder
);
// Generated id
Long id = keyHolder.getKey().longValue();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyHolder 에서 생성된 키를 잘 가져오고 계시는 군요! 좋습니닷 다만 keyHolder.getKey()가 null 일 수 있으니, null 체크해서 에러 던지는 로직을 작성해보는 건 어떨까요?


jdbcTemplate.update(
connection -> {
PreparedStatement ps = connection.prepareStatement(sql,new String[]{"id"});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PreparedStatement 를 생성할 때, 두 번째 파라미터에 컬럼명을 지정해서 가져오기 보단 PreparedStatement.RETURN_GENERATED_KEYS 를 사용하면 좋을 것 같아요! 모든 자동 생성된 키를 가져올 수 있어요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants