본문 바로가기

Side Project

#06. [Side Project 1] JSP 로그인, 게시판 만들기 (6) :: 글 삭제

 

■ bbsdelete.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
<%@page import="dao.BbsDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>bbsdelete.jsp</title>
</head>
<body>
 
<%
int seq = Integer.parseInt( request.getParameter("seq") );
System.out.println("seq:" + seq);
 
BbsDao dao = BbsDao.getInstance();
boolean isS = dao.deleteBbs(seq);
 
if(isS){
    %>
    <script type="text/javascript">
    alert("삭제하였습니다");
    location.href = 'bbslist.jsp';
    </script>
    <%
}else{
    %>
    <script type="text/javascript">
    alert("삭제되지 않았습니다");
    location.href = 'bbslist.jsp';
    </script>    
    <%
}
%>
 
</body>
</html>
 
 
 
 
 
 
 
 
cs

 

■ BbsDao.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
public boolean deleteBbs(int seq) {
        
        String sql = " UPDATE BBS "
                    + " SET DEL=1 "
                    + " WHERE SEQ=? ";
        
        Connection conn = null;
        PreparedStatement psmt = null;
        int count = 0;
        
        try {
            conn = DBConnection.getConnection();
            System.out.println("1/6 S deleteBbs");
            
            psmt = conn.prepareStatement(sql);
            psmt.setInt(1, seq);
            System.out.println("2/6 S deleteBbs");
            
            count = psmt.executeUpdate();
            System.out.println("3/6 S deleteBbs");
            
        } catch (Exception e) {        
            System.out.println("fail deleteBbs");
            e.printStackTrace();
        } finally {
            DBClose.close(psmt, conn, null);            
        }
        
        return count>0?true:false;
    }
cs