MemberDAO.java
//회원 상세 조회(아이디 입력값으로 존재 유무 확인)
//내 코드
private String MEMBER_SEARCH="select member_id from member";
public boolean searchMemberId(String inputId) {
List<Member> memberIdList = new ArrayList<>();
try {
conn=JDBCUtil.getConnection();
stmt=conn.prepareStatement(MEMBER_SEARCH);
rs=stmt.executeQuery();
while(rs.next()) {
Member member = new Member();
member.setMemberId(rs.getString("MEMBER_ID"));
memberIdList.add(member);
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
JDBCUtil.close(rs, stmt, conn);
}
for(Member m :memberIdList){
if(m.getMemberId().equals(inputId)){
return true;
}
}
return false;
}
private String MEMBER_GET="select member_id from member";
public Member getMember(Member member) {
Member member =null;
try {
conn = JDBCUtil.getConnection();
stmt = conn.prepareStatement(MEMBER_GET);
stmt.setString(1, member.getMemberId());
rs = stmt.executeQuery();
if(rs.next()) {
member = new Member();
member.setMemberId(rs.getString("MEMBER_ID"));
member.setName(rs.getString("NAME"));
member.setPhoneNumber(rs.getString("PHONE_NUMBER"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.close(rs, stmt, conn);
}
return member;
}
- 원하는 로직을 구현하기 위해 더 많은 코딩 경험과 다양한 알고리즘 문제 풀이들을 학습할 필요가 있을 것 같다.
- JDBC, DB에 대한 이해와 반복적인 학습이 필요할 것 같다.
Reference: