<< Insert >>
package jdbc_concept5.service;
import jdbc_concept5.run.MemberDAO;
import jdbc_concept5.run.MemberDTO;
public class Insert {
private MemberDAO memberDao = new MemberDAO();
public void insertMember(MemberDTO member) {
MemberDTO tmp = memberDao.selectId(member.getId());
if (tmp != null) {
System.out.println(member.getId() + "는 사용중입니다.");
return;
}
int verify = memberDao.insertMember(member);
if (verify != 1) {
System.out.println("등록 과정에서 문제가 발생했습니다");
return;
}
System.out.println("등록완료");
}
}
<< Select >>
package jdbc_concept5.service;
import java.util.ArrayList;
import jdbc_concept5.run.MemberDAO;
import jdbc_concept5.run.MemberDTO;
public class Select {
private MemberDAO memberDao = new MemberDAO();
public void selectAll() {
ArrayList<MemberDTO> members = memberDao.selectAll();
if (members.isEmpty()) {
System.out.println("등록된 정보가 없습니다.");
return;
}
for (MemberDTO member : members) {
System.out.println("번호 : " + member.getNum());
System.out.println("아이디 : " + member.getId());
System.out.println("비밀번호 : " + member.getPw());
System.out.println("이름 : " + member.getName());
System.out.println("이메일 : " + member.getEmail());
System.out.println("");
}
}
public void selectId(String id) {
MemberDTO member = memberDao.selectId(id);
if (member == null) {
System.out.println(id + "는 없는 정보입니다.");
return;
}
System.out.println("번호 : " + member.getNum());
System.out.println("아이디 : " + member.getId());
System.out.println("비밀번호 : " + member.getPw());
System.out.println("이름 : " + member.getName());
System.out.println("이메일 : " + member.getEmail());
}
}
<< Update >>
package jdbc_concept5.service;
import jdbc_concept5.run.MemberDAO;
import jdbc_concept5.run.MemberDTO;
public class Update {
private MemberDAO memberDao = new MemberDAO();
public void updateMember(MemberDTO member, String fixPw) {
MemberDTO tmp = memberDao.selectId(member.getId());
if (tmp == null) {
System.out.println(member.getId() + "는 없는 정보입니다.");
return;
} else if (!tmp.getPw().equals(member.getPw())) {
System.out.println("비밀번호가 틀렸습니다");
return;
}
int verify = memberDao.updateMember(member);
if (verify != 1) {
System.out.println("수정 과정에서 문제가 발생했습니다.");
return;
}
System.out.println("등록 완료");
}
}
<< Delete >>
package jdbc_concept5.service;
import jdbc_concept5.run.MemberDAO;
import jdbc_concept5.run.MemberDTO;
public class Delete {
private MemberDAO memberDao = new MemberDAO();
public void deleteMember(String id, String pw) {
MemberDTO member = memberDao.selectId(id);
if (member == null) {
System.out.println(id + "는 없는 정보입니다.");
return;
} else if (!member.getPw().equals(pw)) {
System.out.println("비밀번호가 틀립니다.");
return;
}
int verify = memberDao.deleteMember(id);
if (verify != 1) {
System.out.println("삭제 과정에서 문제가 발생했습니다.");
return;
}
System.out.println("삭제 완료");
}
}
<< Exit >>
package jdbc_concept5.service;
import jdbc_concept5.run.MemberDAO;
public class Exit {
private MemberDAO memberDao = new MemberDAO();
public void exit() {
memberDao.exit();
}
}
'JAVA + DB' 카테고리의 다른 글
JAVA + DB 실습 (3)(Class.View) (0) | 2022.08.09 |
---|---|
JAVA + DB 실습 (3)(Class.run) (0) | 2022.08.09 |
JAVA + DB 실습(2) (0) | 2022.08.08 |
JAVA + DB 실습(1-2) (0) | 2022.08.06 |
JAVA + DB 실습(1-1) (0) | 2022.08.06 |