-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBookClubDeleteOk.jsp
55 lines (47 loc) · 1.51 KB
/
BookClubDeleteOk.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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>회원탈퇴</title>
</head>
<body>
<%
String postId = request.getParameter("postId");
String pw = request.getParameter("pw");
try{
String DB_URL = "jdbc:mysql://localhost:3306/internetproject"; // 접속할 DB명
String DB_ID = "multi"; // 접속할 아이디
String DB_PASSWORD = "abcd"; // 접속할 패스워드
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection(DB_URL, DB_ID, DB_PASSWORD); // DB에 접속
String sql = "select * from User where password = ?"; //SQL문 작성
//PreparedStatement 생성(SQL문의 형틀을 정의)
PreparedStatement pstmt1 = con.prepareStatement(sql);
pstmt1.setString(1, pw);
// sql문 실행
ResultSet rs = pstmt1.executeQuery();
if(rs.next()){ // 성공
String jsql = "delete from clubpost where postId=?";
PreparedStatement pstmt3 = con.prepareStatement(jsql);
pstmt3.setString(1, postId);
pstmt3.executeUpdate();
%>
<script>
alert("게시물 삭제가 완료되었습니다.");
location.href = "BookClub.jsp?clubId=1"
</script>
<% }else{ // 실패 %>
<script>
alert("비밀번호가 틀렸습니다.");
location.href = "BookClubDelete.jsp?postId=<%=postId%>"
</script>
<% }
} catch (Exception e) {
out.println(e);
}
%>
</body>
</html>