programming/jsp

jsp 회원가입

히연쓰 2021. 5. 3. 17:16

........... 사실 혼자 할 줄 모른다 .......

배운거 적어놓는거다 ..... 그래야 안 까먹고 다음에도 사용하니 흑흑

혼자 좀 할 줄 알아라 ...... 멍청아

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@100;300;400;500;700;900&display=swap" rel="stylesheet">
<script src="js.jquery-3.6.0.min.js"></script>
 
 
<style>
    * {margin:0; padding:0;}
    body {
        font-family: "Noto Sans KR";
    }
    table {
        border: none;
        border-collapse: collapse;
        border-top: 1px solid #d9d9d9;
    }
    table tr th {
        background-color: #f8f8f8;
        
    }
    table tr th,table tr td {
        padding:15px;
        border-bottom: 1px solid #d9d9d9;
    }
    table tr td input[type="text"],table tr td input[type="password"], table tr td select {
        height: 30px;
        border: 1px solid #d9d9d9;
        padding:5px;
        border-radius: 3px;
        width:50%;
    }
    table tr td select {
        width:120px;
    }
 
    .formBox {
        width:1000px;
        margin: 100px auto;
    }
    .formBox h2 {
        margin-bottom: 50px;
        text-align: center;
    }
    .formBox .btns {
        text-align: center;
        margin-top: 50px;
    }
    .formBox .btns * {
        display: inline-block;
        width:150px;
        height: 50px;
        border: none;
        border-radius: 5px;
        box-shadow: 0 5px 5px rgba(0,0,0,0.1);
        font-size: 16px;
        font-weight: 500;
        background-color: rgb(109, 109, 109);
        color:#fff;
    }
    .formBox .btns #join {
        background-color: rgb(1, 121, 177);
    }
 
</style>
</head>
<body>
    <div class="formBox" id="join">
        <h2>회원가입</h2>
        <form action="member_join_action.jsp" method="POST">
            <table>
                <colgroup>
                    <col style="width:150px">
                    <col style="width:850px">
                </colgroup>
                <tbody>
                    <tr>
                        <th>ID</th>
                        <td><input type="text" name="id"></td>
                    </tr>
                    <tr>
                        <th>NAME</th>
                        <td><input type="text" name="name"></td>
                    </tr>
                    <tr>
                        <th>PASSWORD</th>
                        <td><input type="text" name="password"></td>
                    </tr>
                    <tr>
                        <th>E-MAIL</th>
                        <td><input type="text" name="email"></td>
                    </tr>
                    <tr>
                        <th>PHONE</th>
                        <td><input type="text" name="phone"></td>
                    </tr>
                    <tr>
                        <th>INTEREST</th>
                        <td>
                            <select name="interest" id="">
                                <option value="JAVA">JAVA</option>
                                <option value="PYTHON">PYTHON</option>
                                <option value="VUE">VUE</option>
                                <option value="HTML">HTML</option>
                                <option value="JSP">JSP</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>AGE</th>
                        <td>
                            <select name="age" id="">
                                <option value="10">10</option>
                                <option value="20">20</option>
                                <option value="30">30</option>
                                <option value="40">40</option>
                                <option value="50">50</option>
                            </select>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div class="btns">
                <input type="submit" value="회원가입" id="join">
                <input type="reset" value="취소" id="cancel">
            </div>
        </form>
    </div>
    <script src ="js/join.js">
    </script>
</body>
</html>
cs

member_join.jsp

member_join.jsp

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<%@ page import="com.heeyeon.model.MemberDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <%
        request.setCharacterEncoding("UTF-8");
    %>
    <jsp:useBean id="memberBean" class="com.heeyeon.model.MemberBean">
        <jsp:setProperty name="memberBean" property = "*" />
    </jsp:useBean>
    <%
        MemberDao memberDao = new MemberDao();
        int result = memberDao.insertMember(memberBean);
        //out.println("member02테이블에 영향을 미친 갯수는 : "+ result);
        if(result>0){
    %>
            <script>
                alert("회원가입이 완료 되었습니다.");
                location.href="member_list.jsp";
            </script>
    <%            
        } else {
    %>
            <script>
                alert("회원가입에 실패하였습니다.");
                location.href="member_join.jsp";
            </script>
    <%
        }
    %>
</body>
</html>
 
 
cs

member_join_action.jsp

member_join_action.jsp

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<%@ page import="com.heeyeon.model.MemberBean"%>
<%@ page import="com.heeyeon.model.MemberDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@100;300;400;500;700;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/layout.css">
</head>
<body>
 
    <!--     no값을 받아서.... -->
    <!--     한사람에 대한 정보를 뽑아온다... -->
    <%
        int no = Integer.parseInt(request.getParameter("no"));
        MemberDao  memberDao = new MemberDao(); //Database Access Object
        MemberBean  memberBean = memberDao.getSelectOne(no);
    %>
    <div class="formBox" id="update">
        <h2>회원정보 수정</h2>
        <form action="member_update_action.jsp" method="POST">
            <table>
                <colgroup>
                    <col style="width:150px">
                    <col style="width:850px">
                </colgroup>
                <tbody>
<!--                     <tr> -->
<!--                         <th>ID</th> -->
<!--                         <td><input type="text" name="id" readonly></td> -->
<!--                     </tr> -->
                    <tr>
                        <th>NAME</th>
                        <td><%=memberBean.getName()%></td>
                    </tr>
                    
                    <tr>
                        <th>E-MAIL</th>
                        <td><%=memberBean.getEmail()%></td>
                    </tr>
                    <tr>
                        <th>PHONE</th>
                        <td><%=memberBean.getPhone()%></td>
                    </tr>
                    <tr>
                        <th>INTEREST</th>
                        <td>
                            <%=memberBean.getInterest()%>
                        </td>
                    </tr>
                    <tr>
                        <th>AGE</th>
                        <td>
                            <%=memberBean.getAge()%>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div class="btns">
                <a href="member_update.jsp?no=<%=memberBean.getNo()%>">회원 수정</a>
                <a href="member_delete.jsp?no=<%=memberBean.getNo()%>">회원 탈퇴</a>
                <a href="member_list.jsp">회원 목록</a>
                <a href="member_join.jsp">회원 가입</a>
            </div>
        </form>
    </div>
</body>
</html>
 
cs

-> member_info.jsp

 회원 수정 버튼을 눌러주면 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<%@ page import="com.heeyeon.model.MemberBean"%>
<%@ page import="com.heeyeon.model.MemberDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@100;300;400;500;700;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/layout.css">
</head>
<body>
 
    <!--     no값을 받아서 -->
    <!--     한사람에 대한 정보를 뽑아온다 -->
    <%
        int no = Integer.parseInt(request.getParameter("no"));
        MemberDao  memberDao = new MemberDao(); //Database Access Object
        MemberBean  memberBean = memberDao.getSelectOne(no);
    %>
    <div class="formBox" id="update">
        <h2>회원정보 수정</h2>
        <form action="member_update_action.jsp" method="POST">
            <table>
                <colgroup>
                    <col style="width:150px">
                    <col style="width:850px">
                </colgroup>
                <tbody>
<!--                     <tr> -->
<!--                         <th>ID</th> -->
<!--                         <td><input type="text" name="id" readonly></td> -->
<!--                     </tr> -->
                    <tr>
                        <th>NAME</th>
                        <td><input type="text" name="name" value="<%=memberBean.getName()%>"></td>
                    </tr>
                    <tr>
                        <th>PASSWORD</th>
                        <td><input type="text" name="password" value="<%=memberBean.getPassword()%>"></td>
                    </tr>
                    <tr>
                        <th>E-MAIL</th>
                        <td><input type="text" name="email" value="<%=memberBean.getEmail()%>"></td>
                    </tr>
                    <tr>
                        <th>PHONE</th>
                        <td><input type="text" name="phone" value="<%=memberBean.getPhone()%>"></td>
                    </tr>
                    <tr>
                        <th>INTEREST</th>
                        <td>
                            <select name="interest" id="">
                                <option value="JAVA">JAVA</option>
                                <option value="PYTHON">PYTHON</option>
                                <option value="VUE">VUE</option>
                                <option value="HTML">HTML</option>
                                <option value="JSP">JSP</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>AGE</th>
                        <td>
                            <select name="age" id="">
                                <option value="10">10</option>
                                <option value="20">20</option>
                                <option value="30">30</option>
                                <option value="40">40</option>
                                <option value="50">50</option>
                            </select>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div class="btns">
                <input type="hidden" name="no" value="<%= memberBean.getNo()%>">
                <input type="submit" value="회원 정보 수정" id="join">
                <input type="reset" value="취소" id="cancel">
            </div>
        </form>
    </div>
</body>
</html>
cs

-> member_update.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<%@page import="com.heeyeon.model.MemberDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <%
        request.setCharacterEncoding("UTF-8");    
    %>
    <jsp:useBean id="memberBean" class="com.heeyeon.model.MemberBean">
        <jsp:setProperty name="memberBean" property="*"  />
    </jsp:useBean>
    <%
        int no =  Integer.parseInt(request.getParameter("no"));
        MemberDao memberDao = new MemberDao();
        String dbPassword = memberDao.getPassword(no);
        if(dbPassword.equals(memberBean.getPassword())){
            //넘겨온 패스워드랑  db에서 뽑아온 패스워드랑 같다.
            //update하고 list로 다시 보내주기....
            int result = memberDao.updateMember(memberBean);
            System.out.println(result);
            response.sendRedirect("member_list.jsp");
        } else {
    %>
            <script>
                alert("비밀번호가 잘못 되었습니다.");
                history.back();
            </script>    
    <%
        }
    %>
</body>
</html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cs

-> member_update_action.jsp

member_update.jsp

무언가를 수정하고 회원 정보 수정 버튼을 누르면

 

나는 molayo에 이메일 뒷 부분을 저렇게 수정했더니 member_list에 변경되었다.

다음으로,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<%@ page import="com.heeyeon.model.MemberBean"%>
<%@ page import="com.heeyeon.model.MemberDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link
    href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@100;300;400;500;700;900&display=swap"
    rel="stylesheet">
<link rel="stylesheet" href="css/layout.css">
</head>
<body>
 
    <!--     no값을 받아서.... -->
    <!--     한사람에 대한 정보를 뽑아온다... -->
    <%
        int no = Integer.parseInt(request.getParameter("no"));
        MemberDao  memberDao = new MemberDao(); //Database Access Object
        MemberBean  memberBean = memberDao.getSelectOne(no);
    %>
    <div class="formBox" id="update">
        <h2>회원정보 수정</h2>
        <form action="member_delete_action.jsp" method="POST">
            <table>
                <colgroup>
                    <col style="width: 150px">
                    <col style="width: 850px">
                </colgroup>
                <tbody>
                    <tr>
                        <th>ID</th>
                        <td><input type="text" name="name" value="<%=memberBean.getId()%>"></td>
                    </tr>
                    <tr>
                        <th>NAME</th>
                        <td><input type="text" name="name" value="<%=memberBean.getName()%>"></td>
                    </tr>
                    <tr>
                        <th>PASSWORD</th>
                        <td><input type="password" name="password"
                            value="<%=memberBean.getPassword()%>"></td>
                    </tr>
                </tbody>
            </table>
            <div class="btns">
                <input type="hidden" name="no" value="<%=memberBean.getNo()%>">
                <input type="submit" value="회원 탈퇴" id="join"> 
                <input type="reset" value="취소" id="cancel">
                <a href="member_list.jsp">회원목록</a>
            </div>
        </form>
    </div>
</body>
</html>
cs

i

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<%@page import="com.heeyeon.model.MemberDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <%
        request.setCharacterEncoding("UTF-8");    
    %>
    <jsp:useBean id="memberBean" class="com.heeyeon.model.MemberBean">
        <jsp:setProperty name="memberBean" property="*"  />
    </jsp:useBean>
    <%
        int no =  Integer.parseInt(request.getParameter("no"));
        MemberDao memberDao = new MemberDao();
        String dbPassword = memberDao.getPassword(no);
        if(dbPassword.equals(memberBean.getPassword())){
            //넘겨온 패스워드랑  db에서 뽑아온 패스워드랑같음
            //update하고 list로 다시 보내줌
            int result = memberDao.deleteMember(no);
            System.out.println(result);
            response.sendRedirect("member_list.jsp");
        } else {
    %>
            <script>
                alert("비밀번호가 잘못 되었습니다.");
                history.back();
            </script>    
    <%
        }
    %>
</body>
</html>
 
 
cs

->member_delete_action.jsp

member_info에서 회원 탈퇴 하기 체크해보기
이런 화면이 나온다 .. 근데 ... 회원 목록이 왜저러지 .. -> member_delete.jsp
member_list.jsp에서 삭제된 것을 알 수 있음.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@charset "UTF-8";
 
{
    margin: 0;
    padding: 0;
}
 
body {
    font-family: "Noto Sans KR";
}
{
    text-decoration:none;
    color:inherit;
}
table {
    border: none;
    border-collapse: collapse;
    border-top: 1px solid #d9d9d9;
}
 
table tr th {
    background-color: #f8f8f8;
}
 
table tr th, table tr td {
    padding: 15px;
    border-bottom: 1px solid #d9d9d9;
}
 
table tr td input[type="text"], table tr td input[type="password"],
    table tr td select {
    height: 30px;
    border: 1px solid #d9d9d9;
    padding: 5px;
    border-radius: 3px;
    width: 50%;
}
 
table tr td select {
    width: 120px;
}
 
.formBox {
    width: 1000px;
    margin: 100px auto;
}
 
.formBox h2 {
    margin-bottom: 50px;
    text-align: center;
}
 
.formBox .btns {
    text-align: center;
    margin-top: 50px;
}
 
.formBox .btns * {
    display: inline-block;
    width: 150px;
    height: 50px;
    border: none;
    border-radius: 5px;
    box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
    font-size: 16px;
    font-weight: 500;
    background-color: rgb(109, 109, 109);
    color: #fff;
}
 
.formBox .btns #join {
    background-color: rgb(1, 121, 177);
}
 
#list tbody td {
    text-align: center;
}
#list tbody tr:hover {
    background-color:#000;
    color:#fff;    
}
 
cs

-> css파일

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.heeyeon.model;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
 
public class MemberDao {
    
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:xe";
    String id = "heeyeon";
    String pw = "1234";
    
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    
    //jsp에서 각가의 페이지에서 했던 일을 MemberDao 의 메서드로 바꾸어 처리한다.
    public int insertMember(MemberBean memberBean) {
        int result = 0;
        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url,id,pw);
            String sql = "INSERT INTO MEMBER03 VALUES (MEMBER_SEQ.NEXTVAL,?,?,?,?,?,?,?)";
            pstmt = con.prepareStatement(sql);
            pstmt.setString(1, memberBean.getId());
            pstmt.setString(2, memberBean.getName());
            pstmt.setString(3, memberBean.getPassword());
            pstmt.setString(4, memberBean.getEmail());
            pstmt.setString(5, memberBean.getPhone());
            pstmt.setString(6, memberBean.getInterest());
            pstmt.setString(7, memberBean.getAge());
            result = pstmt.executeUpdate();
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if(pstmt!=null) pstmt.close();
                if(con!=null) pstmt.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }
    
    public ArrayList<MemberBean> showAllMember() {
        ArrayList<MemberBean> memberList = new ArrayList<MemberBean>();
        
        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url, id, pw);
            String sql = "SELECT * FROM MEMBER03";
            pstmt = con.prepareStatement(sql);
            rs = pstmt.executeQuery();
            while(rs.next()) {
                MemberBean memberBean = new MemberBean();
                memberBean.setNo(rs.getInt("no"));
                memberBean.setId(rs.getString("id"));
                memberBean.setName(rs.getString("name"));
                memberBean.setPassword(rs.getString("password"));
                memberBean.setEmail(rs.getString(5));
                memberBean.setPhone(rs.getString(6));
                memberBean.setInterest(rs.getString(7));
                memberBean.setAge(rs.getString(8));
                memberList.add(memberBean);
            }
            
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if(rs!=null) rs.close();
                if(pstmt!=null) pstmt.close();
                if(con!=null) con.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return memberList;
    }
    
 
    public MemberBean getSelectOne(int no) {
        MemberBean memberBean = new MemberBean();
        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url, id, pw);
            String sql = "SELECT * FROM MEMBER03 WHERE NO = ?";
            pstmt = con.prepareStatement(sql);
            pstmt.setInt(1, no);
            rs = pstmt.executeQuery();
            if(rs.next()) {
                memberBean.setNo(rs.getInt("no"));
                memberBean.setId(rs.getString("id"));
                memberBean.setName(rs.getString(3));
                memberBean.setPassword(rs.getString(4));
                memberBean.setEmail(rs.getString(5));
                memberBean.setPhone(rs.getString(6));
                memberBean.setInterest(rs.getString(7));
                memberBean.setAge(rs.getString(8));
            }
            
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if(rs!=null) rs.close();
                if(pstmt!=null) rs.close();
                if(con!=null) rs.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return memberBean;
    }
    
    
    public String getPassword(int no) {
        String password = ""
        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url,id,pw);
            String sql = "SELECT PASSWORD FROM MEMBER03 WHERE NO = ?";
            pstmt = con.prepareStatement(sql);
            pstmt.setInt(1, no);
            //insert, update, delete 는 int를 반환받음
            //select 는 ResultSet을 반환받음
            rs = pstmt.executeQuery();
            if(rs.next()) {
                password = rs.getString("PASSWORD");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if(rs!=null) rs.close();
                if(pstmt!=null) pstmt.close();
                if(con!=null) con.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return password;
    }
    
    public int updateMember(MemberBean memberBean) {
        //연결하기...
        int result = 0;
        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url, id, pw);
            
            String sql = "UPDATE MEMBER03 SET NAME = ?,EMAIL = ?,PHONE = ?,INTEREST = ?,AGE = ? WHERE NO = ?";
            pstmt = con.prepareStatement(sql);
            pstmt.setString(1, memberBean.getName());
            pstmt.setString(2, memberBean.getEmail());
            pstmt.setString(3, memberBean.getPhone());
            pstmt.setString(4, memberBean.getInterest());
            pstmt.setString(5, memberBean.getAge());
            pstmt.setInt(6, memberBean.getNo());
            result = pstmt.executeUpdate();
            
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if(pstmt!=null) pstmt.close();
                if(con!=null) con.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }
    public int deleteMember(int no) {
        int result = 0;
        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url, id, pw);
            String sql = "DELETE FROM MEMBER03 WHERE NO = ?";
            pstmt = con.prepareStatement(sql);
            pstmt.setInt(1,no);
            result = pstmt.executeUpdate();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if(pstmt!=null) pstmt.close();
                if(con!=null) con.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }
    
}
 
 
 
 
 
cs

-> MemberDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.heeyeon.model;
 
public class MemberBean {
    private int no;
    private String id;
    private String name;
    private String password;
    private String email;
    private String phone;
    private String interest;
    private String age;
 
    public MemberBean() {
        
    }
    
    
    public MemberBean(int no, String id, String name, String password, String email, String phone, String interest,
            String age) {
        super();
        this.no = no;
        this.id = id;
        this.name = name;
        this.password = password;
        this.email = email;
        this.phone = phone;
        this.interest = interest;
        this.age = age;
    }
    public int getNo() {
        return no;
    }
    public void setNo(int no) {
        this.no = no;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getInterest() {
        return interest;
    }
    public void setInterest(String interest) {
        this.interest = interest;
    }
    public String getAge() {
        return age;
    }
    public void setAge(String age) {
        this.age = age;
    }
    
    
    @Override
    public String toString() {
        return "MemberBean [no=" + no + ", id=" + id + ", name=" + name + ", password=" + password + ", email=" + email
                + ", phone=" + phone + ", interest=" + interest + ", age=" + age + "]";
    }
    
    
    
}
 
cs

-> MemberBean.java

 

java 파일 목록