[JDBC] MVC Exercise

Joy๐ŸŒฑยท2023๋…„ 1์›” 26์ผ
0

๐Ÿค– Exercise

๋ชฉ๋ก ๋ณด๊ธฐ
2/6
post-thumbnail

๐Ÿ’โ€ Java์™€ Oracle SQL์„ JDBC๋กœ ์—ฐ๋™ํ•˜์—ฌ TBL_MEMBER ํ…Œ์ด๋ธ”์„ ์กฐํšŒ(SELECT), ํ…Œ์ด๋ธ”์— ๊ฐ’์„ ์‚ฝ์ž…(INSERT), ์ˆ˜์ •(UPDATE), ์‚ญ์ œ(DELETE)ํ•  ์ˆ˜ ์žˆ๋„๋ก MVC๊ตฌ์กฐ๋กœ ์ด๋ฃจ์–ด์ง„ ํšŒ์›๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”!


๐Ÿ“Œ ์ดˆ๊ธฐ Setting

โ—ผ JDBCTemplate Class

public class JDBCTemplate {

	/* Connection์„ returnํ•˜๋Š” ๋ฉ”์†Œ๋“œ */
	public static Connection getConnection() {
		
		Connection conn = null;
		Properties prop = new Properties();
		
		try {
			prop.load(new FileReader("config/driver.properties"));
			
			String driver = prop.getProperty("driver");
			String url = prop.getProperty("url");
			
			Class.forName(driver);
			
			conn = DriverManager.getConnection(url, prop);
			
			/* auto commit์ด ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ์œผ๋‚˜,
			 * ํ”„๋กœ๊ทธ๋žจ ๋‚ด์—์„œ ์ž‘์—… ๋‹จ์œ„๋ณ„๋กœ commit๊ณผ rollback์„ ํŒ๋‹จํ•˜์—ฌ ์ˆ˜ํ–‰ํ•˜๊ณ ์žํ•˜๋ฏ€๋กœ
			 * auto commit์„ false๋กœ ์„ค์ • */
			conn.setAutoCommit(false);
			
			
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} 
		
		return conn;
		
	}
	
	/* Connection์„ closeํ•  ๋ฉ”์†Œ๋“œ */
	public static void close(Connection conn) {
		try {
			if(conn != null && !conn.isClosed()) {
				conn.close();
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	/* Statement๋ฅผ closeํ•  ๋ฉ”์†Œ๋“œ */
	public static void close(Statement stmt) {
		try {
			if(stmt != null && !stmt.isClosed()) {
				stmt.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	/* ResultSet์„ closeํ•  ๋ฉ”์†Œ๋“œ */
	public static void close(ResultSet rset) {
		try {
			if(rset != null && !rset.isClosed()) {
				rset.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	/* ---------์ž๋™ commit์„ ์ˆ˜๋™ commit์œผ๋กœ ๋ณ€๊ฒฝ--------- */
	
	/* ๋ชจ๋‘ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์‹คํ–‰์ด ์™„๋ฃŒ๋˜๋ฉด, commitํ•  ๋ฉ”์†Œ๋“œ */
	public static void commit(Connection conn) {
		try {
			if(conn != null && !conn.isClosed()) { // :conn ๊ฐ์ฒด๊ฐ€ ์กด์žฌํ•œ๋‹ค๋ฉด, commmit
				conn.commit();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	/* ํ•˜๋‚˜๋ผ๋„ ์‹คํ–‰๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, rollbackํ•  ๋ฉ”์†Œ๋“œ */
	public static void rollback(Connection conn) {
		try {
			if(conn != null && !conn.isClosed()) { // :conn ๊ฐ์ฒด๊ฐ€ ์กด์žฌํ•œ๋‹ค๋ฉด, rollback
				conn.rollback();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}

๐Ÿ‘‰ DTO

โ—ผ MemberDTO Class

public class MemberDTO {
	
	/*
	  MEMBER_NO NUMBER PRIMARY KEY,
	  MEMBER_ID VARCHAR2(30) UNIQUE,
	  MEMBER_PWD VARCHAR2(30) NOT NULL,
	  MEMBER_NAME VARCHAR2(30),
	  GENDER VARCHAR2(10) CHECK(GENDER IN ('M', 'F')),
	  EMAIL VARCHAR2(50),
	  PHONE VARCHAR2(30),
	  ADDRESS VARCHAR2(100),
	  AGE NUMBER CHECK(AGE > 0),
	  ENROLL_DATE DATE DEFAULT SYSDATE
	 */

	/* ํ•„๋“œ */
	private int memberNo;
	private String memberId;
	private String memberPwd;
	private String memberName;
	private String gender;
	private String email;
	private String phone;
	private String address;
	private int age;
	private Date enrollDate;
    
    /* ๊ธฐ๋ณธ ์ƒ์„ฑ์ž, ๋ชจ๋“  ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ์ƒ์„ฑ์ž */
    
    /* getter & setter */
    
    /* toString */

๐Ÿ‘‰ Views

โ—ผ MemberMenu Class

public class MemberMenu {
	
	/* ์ˆœ์„œ ์ •๋ฆฌ
		MemberMenu(view)์—์„œ ํ•„์š”ํ•œ ๋ฉ”์†Œ๋“œ ์ƒ์„ฑ ํ›„ Controller ํ˜ธ์ถœ
		MemberController ๋ฉ”์†Œ๋“œ ์ƒ์„ฑ ํ›„, Service ํ˜ธ์ถœํ•˜๋ฉด์„œ ๊ฐ’ ๋ฐ›๊ธฐ
		MemberService ๋ฉ”์†Œ๋“œ ์ƒ์„ฑ ํ›„, DAO ํ˜ธ์ถœํ•˜๋ฉด์„œ ๊ฐ’ ๋ฐ›๊ธฐ
		MemberDAO ์ฟผ๋ฆฌ์™€ ๋งคํ•‘ํ•œ ํ›„ Service๋กœ ๊ฐ’ ๋ฆฌํ„ด
	 */
	
	private Scanner sc = new Scanner(System.in);

	public void displayMenu() {
		
		MemberController memberController = new MemberController();
		
		do {
			System.out.println("\n *** ํšŒ์› ๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ *** \n");
			System.out.println("1. ์ƒˆ ํšŒ์› ๋“ฑ๋ก");
			System.out.println("2. ๋ชจ๋“  ํšŒ์› ์กฐํšŒ");
			System.out.println("3. ์•„์ด๋””๋กœ ํšŒ์› ์กฐํšŒ");
			System.out.println("4. ์„ฑ๋ณ„๋กœ ํšŒ์› ์กฐํšŒ");
			System.out.println("5. ์•”ํ˜ธ ์ˆ˜์ •");
			System.out.println("6. ์ด๋ฉ”์ผ ๋ณ€๊ฒฝ");
			System.out.println("7. ์ „ํ™”๋ฒˆํ˜ธ ๋ณ€๊ฒฝ");
			System.out.println("8. ์ฃผ์†Œ ๋ณ€๊ฒฝ");
			System.out.println("9. ํšŒ์› ํƒˆํ‡ด");
			System.out.print("๋ฒˆํ˜ธ ์„ ํƒ : ");
			int no = sc.nextInt();
			
			switch(no) {
				case 1 : memberController.registNewMember(inputMember()); break;
				case 2 : memberController.selectAllMembers(); break;
				case 3 : memberController.searchMemberById(inputMemberId()); break;
				case 4 : memberController.searchMemberByGender(inputGender()); break;
				case 5 : memberController.modifyPassword(inputMemberId(), inputPassword()); break;
				case 6 : memberController.modifyEmail(inputMemberId(), inputEmail()); break;
				case 7 : memberController.modifyPhone(inputMemberId(), inputPhone()); break;
				case 8 : memberController.modifyAddress(inputMemberId(), inputAddress()); break;
				case 9 : memberController.deleteMember(inputMemberId()); break;
				case 0 : return;
				default : System.out.println("์ž˜๋ชป๋œ ๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”. \n");
				
			}
			
		}while(true);
		
	}
	
	public Map<String, String> inputMember() {
		
		/* ํšŒ์›์— ๋Œ€ํ•œ ๋ชจ๋“  ์ •๋ณด๋ฅผ ๋ฌธ์ž์—ด๋กœ๋งŒ ์ž…๋ ฅํ•˜๊ณ , ์ž…๋ ฅํ•œ ์ •๋ณด๋ฅผ HashMap์— ๋ฐ˜ํ™˜ํ•ด์„œ ๋ฆฌํ„ด */
		Map<String, String> map = new HashMap<>();
		
		/* ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ๋ฐ›์•„ ๋งต์— ๋„ฃ๊ธฐ */
		sc.nextLine();
		System.out.print("์‚ฌ์šฉํ•˜์‹ค ์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : ");
		String id = sc.nextLine();
		System.out.print("์•„์ด๋””์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : ");
		String pwd = sc.nextLine();
		System.out.print("์„ฑํ•จ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : ");
		String name = sc.nextLine();
		System.out.print("์„ฑ๋ณ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”(๋‚จ:M/์—ฌ:F) : ");
		String gender = sc.nextLine().toUpperCase();
		System.out.print("์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : ");
		String email = sc.nextLine();
		System.out.print("ํ•ธ๋“œํฐ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”('-'ํฌํ•จ) : ");
		String phone = sc.nextLine();
		System.out.print("๊ฐ„๋žตํ•œ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : ");
		String address = sc.nextLine();
		System.out.print("๋‚˜์ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : ");
		String age = sc.nextLine();
		
		map.put("id", id);
		map.put("pwd", pwd);
		map.put("name", name);
		map.put("gender", gender);
		map.put("email", email);
		map.put("phone", phone);
		map.put("address", address);
		map.put("age", age);

		return map;
	}
	
	public String inputMemberId() {
		
		System.out.print("ํšŒ์› ์•„์ด๋”” : ");
		sc.nextLine();
		
		return sc.nextLine();
	}

	public String inputGender() {
		
		System.out.print("์กฐํšŒํ•  ์„ฑ๋ณ„ ์ž…๋ ฅ(๋‚จ:M/์—ฌ:F) : ");
		sc.nextLine();
		
		return sc.nextLine().toUpperCase();
	}
	
	public String inputPassword() {
		
		System.out.print("์ˆ˜์ •ํ•  ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ : ");
		
		return sc.nextLine();
	}
	
	public String inputEmail() {
		
		System.out.print("์ˆ˜์ •ํ•  ์ด๋ฉ”์ผ ์ž…๋ ฅ : ");
		
		return sc.nextLine();
	}
	
	public String inputPhone() {
		
		System.out.print("์ˆ˜์ •ํ•  ์ „ํ™”๋ฒˆํ˜ธ ์ž…๋ ฅ : ");
		
		return sc.nextLine();
	}
	
	public String inputAddress() {
		
		System.out.print("์ˆ˜์ •ํ•  ์ฃผ์†Œ ์ž…๋ ฅ : ");
		
		return sc.nextLine();
	}
}

โ—ผ MemberResultView Class

public class MemberResultView {
	
	public void displayDmlResult(String code) {
		
		switch(code) {
			case "insertFailed" : System.out.println("ํšŒ์› ๊ฐ€์ž… ์‹คํŒจ :("); break;
			case "updateFailed" : System.out.println("ํšŒ์› ์ •๋ณด ์ˆ˜์ • ์‹คํŒจ :("); break;
			case "deleteFailed" : System.out.println("ํšŒ์› ํƒˆํ‡ด ์‹คํŒจ :("); break;
			case "selectFailed" : System.out.println("ํšŒ์› ์กฐํšŒ ์‹คํŒจ :("); break;
			case "insertSuccess" : System.out.println("ํšŒ์› ๊ฐ€์ž… ์™„๋ฃŒ :)"); break;
			case "updateSuccess" : System.out.println("ํšŒ์› ์ •๋ณด ์ˆ˜์ • ์™„๋ฃŒ :)"); break;
			case "deleteSuccess" : System.out.println("ํšŒ์› ํƒˆํ‡ด ์™„๋ฃŒ :)"); break;
			default : System.out.println("์•Œ ์ˆ˜ ์—†๋Š” ์—๋Ÿฌ ๋ฐœ์ƒ!"); break;
		}
	}
    
	public void display(List<MemberDTO> list) {
		
		for(MemberDTO m : list) {
			System.out.println(m);
		}
	}
    
	public void display(MemberDTO m) {
		
		System.out.println(m);
	}
}

๐Ÿ‘‰ Controller

โ—ผ MemberController Class

public class MemberController { // ๋ฐ›์€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€๊ณต
	
	private MemberResultView memberResultView = new MemberResultView();
	private MemberService memberService = new MemberService();

	/* [1] ์‹ ๊ทœ ํšŒ์› ๋“ฑ๋ก์šฉ ๋ฉ”์†Œ๋“œ */
	public void registNewMember(Map<String, String> requestMap) {
		
		/* Map์œผ๋กœ ์ „๋‹ฌ ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๊บผ๋‚ด MemberDTO์— ๋‹ด์•„ Service๋กœ ์ „๋‹ฌ */
		
		/* 1. ๋ทฐ์—์„œ ์ „๋‹ฌ ๋ฐ›์€ ํŒŒ๋ผ๋ฏธํ„ฐ ๊บผ๋‚ด์„œ ๋ณ€์ˆ˜์— ๋‹ด๊ธฐ */
		String id = requestMap.get("id");
		String pwd = requestMap.get("pwd");
		String name = requestMap.get("name");
		String gender = requestMap.get("gender");
		String email = requestMap.get("email");
		String phone = requestMap.get("phone");
		String address = requestMap.get("address");
		String age = requestMap.get("age");
		
		/* 2. ์ถ”๊ฐ€์ ์œผ๋กœ ํ•„์š”ํ•œ ๊ฐ’์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์ƒ์„ฑํ•˜๊ธฐ */
		
		/* 3. ์„œ๋น„์Šค์ชฝ์œผ๋กœ ์ „๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด DTO ์ธ์Šคํ„ด์Šค์— ๋‹ด๊ธฐ */
		MemberDTO member = new MemberDTO();
	
		member.setMemberId(id);
		member.setMemberPwd(pwd);
		member.setMemberName(name);
		member.setGender(gender);
		member.setEmail(email);
		member.setPhone(phone);
		member.setAddress(address);
		member.setAge(Integer.parseInt(age));
		
		/* 1. Service(๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ์ธ์ž ์ „๋‹ฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด ๋ฐ›์Œ */
		int result = memberService.registNewMember(member);
		
		/* 5. ์„œ๋น„์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•ด ์„ฑ๊ณต ์‹คํŒจ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ ๋ทฐ๋ฅผ ๊ฒฐ์ •ํ•จ */
		if(result > 0) {
			memberResultView.displayDmlResult("insertSuccess");
		} else {
			memberResultView.displayDmlResult("insertFailed");
		}
		
	}
	
	/* [2] ๋ชจ๋“  ํšŒ์› ์ •๋ณด ์กฐํšŒ์šฉ ๋ฉ”์†Œ๋“œ(List๋กœ ์กฐํšŒํ•  ๊ฒƒ) */
	public void selectAllMembers() {
	
		/* 1. Service(๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ์ธ์ž ์ „๋‹ฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด ๋ฐ›์Œ */
		List<MemberDTO> memberList = memberService.selectAllMembers();
		
		/* 2. ์„œ๋น„์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•ด ์„ฑ๊ณต ์‹คํŒจ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ ๋ทฐ๋ฅผ ๊ฒฐ์ •ํ•จ */
		if(memberList != null) {
			memberResultView.display(memberList);
		} else {
			memberResultView.displayDmlResult("selectFailed");
		}
	}
	
	/* [3] ์•„์ด๋””๋ฅผ ์ด์šฉํ•œ ํšŒ์› ์ •๋ณด ๊ฒ€์ƒ‰(MemberDTO๋กœ ํ•œ ๋ช… ํšŒ์› ์ •๋ณด ์กฐํšŒ) */
	public void searchMemberById(String id) { // ์ž…๋ ฅ๋ฐ›์€ id ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋“ค์–ด์˜ด
		
		/* 1. Service(๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ์ธ์ž ์ „๋‹ฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด ๋ฐ›์Œ */
		MemberDTO member = memberService.searchMemberById(id);
				
		/* 3. ์„œ๋น„์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•ด ์„ฑ๊ณต ์‹คํŒจ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ ๋ทฐ๋ฅผ ๊ฒฐ์ •ํ•จ */
		if(member != null) {
			memberResultView.display(member);
		} else {
			memberResultView.displayDmlResult("selectFailed");
		}
		
	}
	
	/* [4] ์„ฑ๋ณ„์„ ์ด์šฉํ•œ ํšŒ์› ์ •๋ณด ๊ฒ€์ƒ‰ (List๋กœ ์กฐํšŒํ•  ๊ฒƒ)*/
	public void searchMemberByGender(String gender) { // ์ž…๋ ฅ๋ฐ›์€ gender ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋“ค์–ด์˜ด

		/* 1. Service(๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ์ธ์ž ์ „๋‹ฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด ๋ฐ›์Œ */
		List<MemberDTO> memberList = memberService.searchMemberByGender(gender);
		
		/* 3. ์„œ๋น„์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•ด ์„ฑ๊ณต ์‹คํŒจ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ ๋ทฐ๋ฅผ ๊ฒฐ์ •ํ•จ */
		if(memberList != null) {
			memberResultView.display(memberList);
		} else {
			memberResultView.displayDmlResult("selectFailed");
		}
		
	}
	
	/* [5] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ */
	public void modifyPassword(String memberId, String password) { // ์ž…๋ ฅ๋ฐ›์€ id, pwd ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋“ค์–ด์˜ด
		
		/* 1. Service(๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ์ธ์ž ์ „๋‹ฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด ๋ฐ›์Œ */
		int result = memberService.modifyPassword(memberId, password);
		
		/* 3. ์„œ๋น„์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•ด ์„ฑ๊ณต ์‹คํŒจ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ ๋ทฐ๋ฅผ ๊ฒฐ์ •ํ•จ */
		if(result > 0) {
			memberResultView.displayDmlResult("updateSuccess");
		} else {
			memberResultView.displayDmlResult("updateFailed");
		}
	}
	
	/* [6] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ด๋ฉ”์ผ ๋ณ€๊ฒฝ */
	public void modifyEmail(String memberId, String email) {

		/* 1. Service(๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ์ธ์ž ์ „๋‹ฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด ๋ฐ›์Œ */
		int result = memberService.modifyEmail(memberId, email);
		
		/* 3. ์„œ๋น„์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•ด ์„ฑ๊ณต ์‹คํŒจ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ ๋ทฐ๋ฅผ ๊ฒฐ์ •ํ•จ */
		if(result > 0) {
			memberResultView.displayDmlResult("updateSuccess");
		} else {
			memberResultView.displayDmlResult("updateFailed");
		}
	}
	
	/* [7] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ „ํ™”๋ฒˆํ˜ธ ๋ณ€๊ฒฝ */
	public void modifyPhone(String memberId, String phone) {
		
		/* 1. Service(๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ์ธ์ž ์ „๋‹ฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด ๋ฐ›์Œ */
		int result = memberService.modifyPhone(memberId, phone);
		
		/* 3. ์„œ๋น„์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•ด ์„ฑ๊ณต ์‹คํŒจ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ ๋ทฐ๋ฅผ ๊ฒฐ์ •ํ•จ */
		if(result > 0) {
			memberResultView.displayDmlResult("updateSuccess");
		} else {
			memberResultView.displayDmlResult("updateFailed");
		}
	}
	
	/* [8] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ฃผ์†Œ ๋ณ€๊ฒฝ */
	public void modifyAddress(String memberId, String address) {
		
		/* 1. Service(๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ์ธ์ž ์ „๋‹ฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด ๋ฐ›์Œ */
		int result = memberService.modifyAddress(memberId, address);
		
		/* 2. ์„œ๋น„์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•ด ์„ฑ๊ณต ์‹คํŒจ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ ๋ทฐ๋ฅผ ๊ฒฐ์ •ํ•จ */
		if(result > 0) {
			memberResultView.displayDmlResult("updateSuccess");
		} else {
			memberResultView.displayDmlResult("updateFailed");
		}
	}
	
	/* [9] ํšŒ์› ์ •๋ณด ์‚ญ์ œ์šฉ ๋ฉ”์†Œ๋“œ */
	public void deleteMember(String memberId) {

		/* 1. Service(๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง)๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ์ธ์ž ์ „๋‹ฌํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ด ๋ฐ›์Œ */
		int result = memberService.deleteMember(memberId);
		
		/* 2. ์„œ๋น„์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ด์šฉํ•ด ์„ฑ๊ณต ์‹คํŒจ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ ๋ทฐ๋ฅผ ๊ฒฐ์ •ํ•จ */
		if(result > 0) {
			memberResultView.displayDmlResult("deleteSuccess");
		} else {
			memberResultView.displayDmlResult("deleteFailed");
		}
	}
}

๐Ÿ‘‰ Service

โ—ผ MemberService Class

public class MemberService {

	private MemberDAO memberDAO = new MemberDAO();
	
	/* [1] ์‹ ๊ทœ ํšŒ์› ๋“ฑ๋ก์šฉ ๋ฉ”์†Œ๋“œ */
	public int registNewMember(MemberDTO member) {
		
		/* 1. Connection ์ƒ์„ฑ */
		Connection conn = getConnection();
		
		/* 2. ์„ฑ๊ณต์—ฌ๋ถ€ ํŒ๋‹จํ•  ๊ฐ’ ์ดˆ๊ธฐํ™” */
		int result = 0;
		
		/* 3. DAO ๋ฉ”์†Œ๋“œ๋กœ ์ „๋‹ฌ ๋ฐ›์€ ๊ฐ’ ๋„˜๊ฒจ์„œ insert */
		/* TBL_MEMBER์— insert */
		int memberResult = memberDAO.insertNewMember(conn, member);
		
		/* 4. ์„ฑ๊ณต ์—ฌ๋ถ€ ํŒ๋‹จ ํ›„ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ */
		if(memberResult > 0) {
			commit(conn);
			result = 1;
		} else {
			rollback(conn);
		}
		
		/* 5. Connection ๋‹ซ๊ธฐ */
		close(conn);
		
		/* 6. ๊ฒฐ๊ณผ ๊ฐ’ ๋ฐ˜ํ™˜ */
		return result;
	}

	/* [2] ๋ชจ๋“  ํšŒ์› ์ •๋ณด ์กฐํšŒ์šฉ ๋ฉ”์†Œ๋“œ */
	public List<MemberDTO> selectAllMembers() {
		
		/* 1. Connection ์ƒ์„ฑ */
		Connection conn = getConnection();
		
		/* 2. DAO์˜ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฆฌํ„ด ๋ฐ›๊ธฐ */
		List<MemberDTO> memberList = memberDAO.selectAllMembers(conn);
		
		/* 3. ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ (select์˜ ๊ฒฝ์šฐ commit, rollback์ด ํ•„์š”์—†์œผ๋ฏ€๋กœ ์ƒ๋žต) */
		/* 4. Connection ๋ฐ˜๋‚ฉ */
		close(conn);
		
		return memberList; // ์ตœ์ข… ๋ฐ˜ํ™˜
	}

	/* [3] ์•„์ด๋””๋ฅผ ์ด์šฉํ•œ ํšŒ์› ์ •๋ณด ๊ฒ€์ƒ‰์šฉ ๋ฉ”์†Œ๋“œ */
	public MemberDTO searchMemberById(String id) { // Controller๋กœ๋ถ€ํ„ฐ id์ธ์ž ์ „๋‹ฌ ๋ฐ›๊ธฐ
		
		/* 1. Connection ์ƒ์„ฑ */
		Connection conn = getConnection();

		/* 2. DAO์˜ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฆฌํ„ด ๋ฐ›๊ธฐ */
		MemberDTO member = memberDAO.searchMemberById(conn, id);
		
		/* 3. ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ (select์˜ ๊ฒฝ์šฐ commit, rollback์ด ํ•„์š”์—†์œผ๋ฏ€๋กœ ์ƒ๋žต) */
		/* 4. Connection ๋ฐ˜๋‚ฉ */
		close(conn);
		
		return member;
	}
	
	/* [4] ์„ฑ๋ณ„์„ ์ด์šฉํ•œ ํšŒ์› ์ •๋ณด ๊ฒ€์ƒ‰์šฉ ๋ฉ”์†Œ๋“œ */
	public List<MemberDTO> searchMemberByGender(String gender) {
		
		/* 1. Connection ์ƒ์„ฑ */
		Connection conn = getConnection();
		
		/* 2. DAO์˜ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฆฌํ„ด ๋ฐ›๊ธฐ */
		List<MemberDTO> memberList = memberDAO.searchMemberByGender(conn, gender);
		
		/* 3. ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ (select์˜ ๊ฒฝ์šฐ commit, rollback์ด ํ•„์š”์—†์œผ๋ฏ€๋กœ ์ƒ๋žต) */
		/* 4. Connection ๋ฐ˜๋‚ฉ */
		close(conn);
				
		return memberList;
	}

	/* [5] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ์šฉ ๋ฉ”์†Œ๋“œ */
	public int modifyPassword(String memberId, String password) {
		
		/* 1. Connection ์ƒ์„ฑ */
		Connection conn = getConnection();
		
		/* 2. ์„ฑ๊ณต์—ฌ๋ถ€ ํŒ๋‹จํ•  ๊ฐ’ ์ดˆ๊ธฐํ™” */
		int result = 0;
		
		/* 3. DAO์˜ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฆฌํ„ด ๋ฐ›๊ธฐ */
		int member = memberDAO.modifyPassword(conn, memberId, password);
		
		/* 4. ์„ฑ๊ณต ์—ฌ๋ถ€ ํŒ๋‹จ ํ›„ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ */
		if(member > 0) {
			commit(conn);
			result = 1;
		} else {
			rollback(conn);
		}
		
		/* 5. Connection ๋‹ซ๊ธฐ */
		close(conn);
		
		/* 6. ๊ฒฐ๊ณผ ๊ฐ’ ๋ฐ˜ํ™˜ */
		return result;
		
		
	}

	/* [6] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ด๋ฉ”์ผ ๋ณ€๊ฒฝ์šฉ ๋ฉ”์†Œ๋“œ */
	public int modifyEmail(String memberId, String email) {
		
		/* 1. Connection ์ƒ์„ฑ */
		Connection conn = getConnection();
		
		/* 2. ์„ฑ๊ณต์—ฌ๋ถ€ ํŒ๋‹จํ•  ๊ฐ’ ์ดˆ๊ธฐํ™” */
		int result = 0;
		
		/* 3. DAO์˜ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฆฌํ„ด ๋ฐ›๊ธฐ */
		int member = memberDAO.modifyEmail(conn, memberId, email);
		
		/* 4. ์„ฑ๊ณต ์—ฌ๋ถ€ ํŒ๋‹จ ํ›„ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ */
		if(member > 0) {
			commit(conn);
			result = 1;
		} else {
			rollback(conn);
		}
		
		/* 5. Connection ๋‹ซ๊ธฐ */
		close(conn);
		
		/* 6. ๊ฒฐ๊ณผ ๊ฐ’ ๋ฐ˜ํ™˜ */
		return result;
	}

	/* [7] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ „ํ™”๋ฒˆํ˜ธ ๋ณ€๊ฒฝ์šฉ ๋ฉ”์†Œ๋“œ */
	public int modifyPhone(String memberId, String phone) {
		
		/* 1. Connection ์ƒ์„ฑ */
		Connection conn = getConnection();
		
		/* 2. ์„ฑ๊ณต์—ฌ๋ถ€ ํŒ๋‹จํ•  ๊ฐ’ ์ดˆ๊ธฐํ™” */
		int result = 0;
		
		/* 3. DAO์˜ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฆฌํ„ด ๋ฐ›๊ธฐ */
		int member = memberDAO.modifyPhone(conn, memberId, phone);
		
		/* 4. ์„ฑ๊ณต ์—ฌ๋ถ€ ํŒ๋‹จ ํ›„ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ */
		if(member > 0) {
			commit(conn);
			result = 1;
		} else {
			rollback(conn);
		}
		
		/* 5. Connection ๋‹ซ๊ธฐ */
		close(conn);
		
		/* 6. ๊ฒฐ๊ณผ ๊ฐ’ ๋ฐ˜ํ™˜ */
		return result;
		
	}

	/* [8] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ฃผ์†Œ ๋ณ€๊ฒฝ์šฉ ๋ฉ”์†Œ๋“œ */
	public int modifyAddress(String memberId, String address) {
		
		/* 1. Connection ์ƒ์„ฑ */
		Connection conn = getConnection();
		
		/* 2. ์„ฑ๊ณต์—ฌ๋ถ€ ํŒ๋‹จํ•  ๊ฐ’ ์ดˆ๊ธฐํ™” */
		int result = 0;
		
		/* 3. DAO์˜ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฆฌํ„ด ๋ฐ›๊ธฐ */
		int member = memberDAO.modifyAddress(conn, memberId, address);
		
		/* 4. ์„ฑ๊ณต ์—ฌ๋ถ€ ํŒ๋‹จ ํ›„ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ */
		if(member > 0) {
			commit(conn);
			result = 1;
		} else {
			rollback(conn);
		}
		
		/* 5. Connection ๋‹ซ๊ธฐ */
		close(conn);
		
		/* 6. ๊ฒฐ๊ณผ ๊ฐ’ ๋ฐ˜ํ™˜ */
		return result;
		
	}

	/* [9] ํšŒ์› ์ •๋ณด ์‚ญ์ œ์šฉ ๋ฉ”์†Œ๋“œ */
	public int deleteMember(String memberId) {
		
		/* 1. Connection ์ƒ์„ฑ */
		Connection conn = getConnection();
		
		/* 2. ์„ฑ๊ณต์—ฌ๋ถ€ ํŒ๋‹จํ•  ๊ฐ’ ์ดˆ๊ธฐํ™” */
		int result = 0;
		
		/* 3. DAO์˜ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ฆฌํ„ด ๋ฐ›๊ธฐ */
		int member = memberDAO.deleteMember(conn, memberId);
		
		/* 4. ์„ฑ๊ณต ์—ฌ๋ถ€ ํŒ๋‹จ ํ›„ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ */
		if(member > 0) {
			commit(conn);
			result = 1;
		} else {
			rollback(conn);
		}
		
		/* 5. Connection ๋‹ซ๊ธฐ */
		close(conn);
		
		/* 6. ๊ฒฐ๊ณผ ๊ฐ’ ๋ฐ˜ํ™˜ */
		return result;
	}
}

๐Ÿ‘‰ DAO

โ—ผ MemberDAO Class

public class MemberDAO {
	
	// ํŒŒ์ผ์„ ์ž…๋ ฅ ๋ฐ›๊ธฐ ์œ„ํ•ด prop ๊ฐ์ฒด ์ƒ์„ฑ ํ›„ ์˜ˆ์™ธ์ฒ˜๋ฆฌ
	private Properties prop = new Properties();
	
	public MemberDAO() {
		try {
			prop.loadFromXML(new FileInputStream("mapper/member-query.xml"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/* [1] ์‹ ๊ทœ ํšŒ์› ๋“ฑ๋ก์šฉ ๋ฉ”์†Œ๋“œ */
	public int insertNewMember(Connection con, MemberDTO member) {
		
		PreparedStatement pstmt = null;
		int result = 0;
		
		String query = prop.getProperty("insertNewMember");
		
		try {
			pstmt = con.prepareStatement(query);
			pstmt.setString(1, member.getMemberId());
			pstmt.setString(2, member.getMemberPwd());
			pstmt.setString(3, member.getMemberName());
			pstmt.setString(4, member.getGender());
			pstmt.setString(5, member.getEmail());
			pstmt.setString(6, member.getPhone());
			pstmt.setString(7, member.getAddress());
			pstmt.setInt(8, member.getAge());
			
			result = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(pstmt);
		}
		
		return result;
	}
	
	/* [2] ๋ชจ๋“  ํšŒ์› ์ •๋ณด ์กฐํšŒ์šฉ ๋ฉ”์†Œ๋“œ */
	public List<MemberDTO> selectAllMembers(Connection conn) {
		
		PreparedStatement pstmt = null;
		ResultSet rset = null;
		
		List<MemberDTO> memberList = null; // ์ตœ์ข… ๋ฐ˜ํ™˜ํ•  ๋ฆฌ์ŠคํŠธ
		
		String query = prop.getProperty("selectAllMembers");
		
		try {
			pstmt = conn.prepareStatement(query);
			rset = pstmt.executeQuery();
			
			memberList = new ArrayList<>();
			
			while(rset.next()) { // ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ, ๋งคํ•‘ํ•˜๋Š” ๊ฒƒ!?
				MemberDTO member = new MemberDTO();
				member.setMemberNo(rset.getInt("MEMBER_NO"));
				member.setMemberId(rset.getString("MEMBER_ID"));
				member.setMemberPwd(rset.getString("MEMBER_PWD"));
				member.setMemberName(rset.getString("MEMBER_NAME"));
				member.setGender(rset.getString("GENDER"));
				member.setEmail(rset.getString("EMAIL"));
				member.setPhone(rset.getString("PHONE"));
				member.setAddress(rset.getString("ADDRESS"));
				member.setAge(rset.getInt("AGE"));
				member.setEnrollDate(rset.getDate("ENROLL_DATE"));
				
				memberList.add(member);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(rset);
			close(pstmt); // conn์€ ์„œ๋น„์Šค์—์„œ ๋‹ซ๊ธฐ
		}

		return memberList;
	}
	
	/* [3] ์•„์ด๋””๋ฅผ ์ด์šฉํ•œ ํšŒ์› ์ •๋ณด ๊ฒ€์ƒ‰์šฉ ๋ฉ”์†Œ๋“œ */
	public MemberDTO searchMemberById(Connection conn, String id) {
		
		PreparedStatement pstmt = null;
		ResultSet rset = null;
		
		MemberDTO member = null;
		
		String query = prop.getProperty("selectMemberById");
		
		try {
			pstmt = conn.prepareStatement(query);
			pstmt.setString(1, id);
			
			rset = pstmt.executeQuery();
			
			while(rset.next()) {
				member = new MemberDTO();
						
				member.setMemberNo(rset.getInt("MEMBER_NO"));
				member.setMemberId(rset.getString("MEMBER_ID"));
				member.setMemberPwd(rset.getString("MEMBER_PWD"));
				member.setMemberName(rset.getString("MEMBER_NAME"));
				member.setGender(rset.getString("GENDER"));
				member.setEmail(rset.getString("EMAIL"));
				member.setPhone(rset.getString("PHONE"));
				member.setAddress(rset.getString("ADDRESS"));
				member.setAge(rset.getInt("AGE"));
				member.setEnrollDate(rset.getDate("ENROLL_DATE"));
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(rset);
			close(pstmt);
		}
		return member;
	}
	
	/* [4] ์„ฑ๋ณ„์„ ์ด์šฉํ•œ ํšŒ์› ์ •๋ณด ๊ฒ€์ƒ‰์šฉ ๋ฉ”์†Œ๋“œ */
	public List<MemberDTO> searchMemberByGender(Connection conn, String gender) {
		
		PreparedStatement pstmt = null;
		ResultSet rset = null;
		
		List<MemberDTO> memberList = null;
		
		String query = prop.getProperty("selectMemberByGender");
		
		try {
			pstmt = conn.prepareStatement(query);
			pstmt.setString(1, gender);
			
			rset = pstmt.executeQuery();
			
			memberList = new ArrayList<>();
			
			while(rset.next()) {
				MemberDTO member = new MemberDTO();
						
				member.setMemberNo(rset.getInt("MEMBER_NO"));
				member.setMemberId(rset.getString("MEMBER_ID"));
				member.setMemberPwd(rset.getString("MEMBER_PWD"));
				member.setMemberName(rset.getString("MEMBER_NAME"));
				member.setGender(rset.getString("GENDER"));
				member.setEmail(rset.getString("EMAIL"));
				member.setPhone(rset.getString("PHONE"));
				member.setAddress(rset.getString("ADDRESS"));
				member.setAge(rset.getInt("AGE"));
				member.setEnrollDate(rset.getDate("ENROLL_DATE"));
				
				memberList.add(member);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(rset);
			close(pstmt);
		}
		
		return memberList;
	}

	/* [5] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ์šฉ ๋ฉ”์†Œ๋“œ */
	public int modifyPassword(Connection conn, String memberId, String password) {
		
		PreparedStatement pstmt = null;
		
		String query = prop.getProperty("updatePassword");
		
		int result = 0;
		
		MemberDTO member = new MemberDTO();
		member.setMemberPwd(password);
		
		try {
			pstmt = conn.prepareStatement(query);
			pstmt.setString(1, member.getMemberPwd());
			pstmt.setString(2, memberId);
			
			result = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(pstmt);
		}
		
		return result;
	}
	
	/* [6] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ด๋ฉ”์ผ ๋ณ€๊ฒฝ์šฉ ๋ฉ”์†Œ๋“œ */
	public int modifyEmail(Connection conn, String memberId, String email) {
		
		PreparedStatement pstmt = null;
		
		String query = prop.getProperty("updateEmail");
		
		int result = 0;
		
		MemberDTO member = new MemberDTO();
		member.setEmail(email);
		
		try {
			pstmt = conn.prepareStatement(query);
			pstmt.setString(1, member.getEmail());
			pstmt.setString(2, memberId);
			
			result = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(pstmt);
		}
		
		return result;
	}

	/* [7] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ „ํ™”๋ฒˆํ˜ธ ๋ณ€๊ฒฝ์šฉ ๋ฉ”์†Œ๋“œ */
	public int modifyPhone(Connection conn, String memberId, String phone) {
		
		PreparedStatement pstmt = null;
		
		String query = prop.getProperty("updatePhone");
		
		int result = 0;
		
		MemberDTO member = new MemberDTO();
		member.setPhone(phone);
		
		try {
			pstmt = conn.prepareStatement(query);
			pstmt.setString(1, member.getPhone());
			pstmt.setString(2, memberId);
			
			result = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(pstmt);
		}
		
		return result;
	}

	/* [8] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ „ํ™”๋ฒˆํ˜ธ ๋ณ€๊ฒฝ์šฉ ๋ฉ”์†Œ๋“œ */
	public int modifyAddress(Connection conn, String memberId, String address) {
		
		PreparedStatement pstmt = null;
		
		String query = prop.getProperty("updateAddress");
		
		int result = 0;
		
		MemberDTO member = new MemberDTO();
		member.setAddress(address);
		
		try {
			pstmt = conn.prepareStatement(query);
			pstmt.setString(1, member.getAddress());
			pstmt.setString(2, memberId);
			
			result = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(pstmt);
		}
		
		return result;
	}
	
	/* [9] ํšŒ์› ์ •๋ณด ์‚ญ์ œ์šฉ ๋ฉ”์†Œ๋“œ */
	public int deleteMember(Connection conn, String memberId) {
		
		PreparedStatement pstmt = null;
		
		String query = prop.getProperty("deleteMember");
		
		int result = 0;
		
		try {
			pstmt = conn.prepareStatement(query);
			pstmt.setString(1, memberId);
			
			result = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(pstmt);
		}
		
		return result;
	}
}

๐Ÿ‘‰ Mapper

โ—ผ member-query.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
	<!-- [1] ์‹ ๊ทœ ํšŒ์› ๋“ฑ๋ก์šฉ ์ฟผ๋ฆฌ -->
	<entry key="insertNewMember">
	INSERT
		INTO TBL_MEMBER A
	(
		A.MEMBER_NO
	,	A.MEMBER_ID
	,	A.MEMBER_PWD
	,	A.MEMBER_NAME
	,	A.GENDER
	,	A.EMAIL
	,	A.PHONE
	,	A.ADDRESS
	,	A.AGE
	,	A.ENROLL_DATE
	)
	VALUES
	(
		SEQ_MEMBER_NO.NEXTVAL
	,	?
	,	?
	,	?
	,	?
	,	?
	,	?
	,	?
	,	?
	,	SYSDATE
	)
	</entry>
	
	<!-- [2] ๋ชจ๋“  ํšŒ์› ์ •๋ณด ์กฐํšŒ์šฉ ์ฟผ๋ฆฌ -->
	<entry key="selectAllMembers">
	SELECT
			*
		FROM TBL_MEMBER
	</entry>
	
	<!-- [3] ์•„์ด๋””๋ฅผ ์ด์šฉํ•œ ํšŒ์› ์ •๋ณด ๊ฒ€์ƒ‰์šฉ ์ฟผ๋ฆฌ -->
	<entry key="selectMemberById">
	SELECT
			*
		FROM TBL_MEMBER
		WHERE MEMBER_ID = ?
	</entry>
	
	<!-- [4] ์„ฑ๋ณ„์„ ์ด์šฉํ•œ ํšŒ์› ์ •๋ณด ๊ฒ€์ƒ‰์šฉ ์ฟผ๋ฆฌ -->
	<entry key="selectMemberByGender">
	SELECT
			*
		FROM TBL_MEMBER
		WHERE GENDER = ?
	</entry>
	
	<!-- [5] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ์šฉ ์ฟผ๋ฆฌ -->
	<entry key="updatePassword">
	UPDATE
			TBL_MEMBER
		SET MEMBER_PWD = ?
		WHERE MEMBER_ID = ?
	</entry>
	
	<!-- [6] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ด๋ฉ”์ผ ๋ณ€๊ฒฝ์šฉ ์ฟผ๋ฆฌ -->
	<entry key="updateEmail">
	UPDATE
			TBL_MEMBER
		SET EMAIL = ?
		WHERE MEMBER_ID = ?
	</entry>
	
	<!-- [7] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ „ํ™”๋ฒˆํ˜ธ ๋ณ€๊ฒฝ์šฉ ์ฟผ๋ฆฌ -->
	<entry key="updatePhone">
	UPDATE
			TBL_MEMBER
		SET PHONE = ?
		WHERE MEMBER_ID = ?
	</entry>
	
	<!-- [8] ์ž…๋ ฅ๋ฐ›์€ ์•„์ด๋””์™€ ์ผ์น˜ํ•˜๋Š” ํšŒ์›์˜ ์ฃผ์†Œ ๋ณ€๊ฒฝ์šฉ ์ฟผ๋ฆฌ -->
	<entry key="updateAddress">
	UPDATE
			TBL_MEMBER
		SET ADDRESS = ?
		WHERE MEMBER_ID = ?
	</entry>
	
	<!-- [9] ํšŒ์› ์ •๋ณด ์‚ญ์ œ์šฉ ๋ฉ”์†Œ๋“œ -->
	<entry key="deleteMember">
	DELETE
		FROM TBL_MEMBER
		WHERE MEMBER_ID = ?
	</entry>

</properties>

๐Ÿ‘‰ Run

โ—ผ Application Class

public class Application {

	public static void main(String[] args) {
		
		new MemberMenu().displayMenu();
		
		System.out.println("ํšŒ์›๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.");
	}
}

๐Ÿ’ฌ Overall Comment

* ์ฒ˜์Œ์œผ๋กœ MVC๊ตฌ์กฐ๋ฅผ ์Šค์Šค๋กœ ์™„์„ฑํ•ด๋ณธ ๊ฒฝํ—˜์ด์—ˆ๋‹ค. ์ˆ˜์—…์—์„œ ๋ฐฐ์šด ๋‚ด์šฉ์„ ํ† ๋Œ€๋กœ ํšŒ์›๊ด€๋ฆฌ 
ํ”„๋กœ๊ทธ๋žจ์„ ์™„์„ฑํ–ˆ๋Š”๋ฐ, ์ฒ˜์Œ์—๋Š” ๊ต‰์žฅํžˆ ๋ง‰๋ง‰ํ–ˆ์ง€๋งŒ ํ•˜๋‚˜ํ•˜๋‚˜ ๋งŒ๋“ค์–ด๊ฐ€๋‹ˆ ๊ตฌ์กฐ๊ฐ€ ์ ์  ํ™•๋ฆฝ๋˜์–ด๊ฐ€๊ณ  
ํ๋ฆ„์„ ์ฝ์„ ์ค„ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค. ์ดํ›„์— MVC ๊ตฌ์กฐ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•  ๋•Œ ์ด๋ฒˆ ๋„์ „์ด 
๊ต‰์žฅํžˆ ํฐ ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™๋‹ค. 
profile
Tiny little habits make me

0๊ฐœ์˜ ๋Œ“๊ธ€