Notice
Recent Posts
Recent Comments
Link
«   2025/01   »
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
Tags
more
Archives
Today
Total
관리 메뉴

soozya

[BACK] 글 삭제하기 본문

👩🏻‍💻프로젝트/👥팀프로젝트

[BACK] 글 삭제하기

soozya 2023. 8. 3. 21:08

[👩🏻‍💻소스코드]

 

[QNAboardDAO.java]

	//9. 글 삭제하기
	public int deleteArticle(int post_num)  {
        int x=-1;
        try {
           con=pool.getConnection();
           sql="delete from qna_post where post_num=? ";
           pstmt=con.prepareStatement(sql);
           pstmt.setInt(1, post_num);
           int delete =pstmt.executeUpdate();

           System.out.println("게시판 글 삭제 성공(delete):"+delete);
           rs=pstmt.executeQuery();
        }catch(Exception e) {
           System.out.println("deleteArticle()=>"+e);
        }finally {
           pool.freeConnection(con,pstmt,rs);
        }
        return x;
	}

 

[QNADeleteProAction.java]

package action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.QNAboardDAO;

public class QNADeleteProAction implements CommandAction {

	@Override
	public String requestPro(HttpServletRequest request, HttpServletResponse response) throws Throwable {
		// TODO Auto-generated method stub

	  String pageNum=request.getParameter("pageNum");
	  int post_num=Integer.parseInt(request.getParameter("post_num"));
	  System.out.println("DeleteProAction에서의 pageNum="+pageNum+", post_num="+post_num);

	  QNAboardDAO dbPro=new QNAboardDAO();
	  int check=dbPro.deleteArticle(post_num); //1:성공 / 0: 실패

	  //2개의 공유값이 필요
	  request.setAttribute("pageNum", pageNum);//삭제 페이지로 이동
	  request.setAttribute("check", check); //데이터 삭제 성공 유무

	  return "/QNAdeletepro.jsp";
	}

}

 


[💻결과]

 

1) 글 목록

 

2) 상세보기에서 '삭제' 선택

 

3) 글 삭제 alert 창 

4) 글 삭제 확인