delete 만들어 볼까..
먼저 view에서 삭제링크 만들어야지
<%@page import="board.model.BoardDao"%> <%@page import="board.model.BoardDto"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% int seq = Integer.parseInt(request.getParameter("seq")); BoardDto boardDto = new BoardDto(); BoardDao boardDao = new BoardDao(); boardDto = boardDao.getView(seq); %> <!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>Insert title here</title> </head> <body> <table> <caption>글 상세보기</caption> <tr> <th>글번호</th> <td><%=boardDto.getSeq()%></td> </tr> <tr> <th>제목</th> <td><%=boardDto.getTitle()%></td> </tr> <tr> <th>이름</th> <td><%=boardDto.getName()%></td> </tr> <tr> <th>조회수</th> <td><%=boardDto.getReadcount()%></td> </tr> <tr> <th>작성시간</th> <td><%=boardDto.getWriteday()%></td> </tr> <tr> <th>내용</th> <td><%=boardDto.getContent()%></td> </tr> </table><br/> <a href = "list.jsp">리스트</a> <a href = "">수정</a> <a href="delete_action.jsp?seq=<%=boardDto.getSeq() %>">삭제</a> </body> </html>
<%@page import="board.model.BoardDao"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% int seq = Integer.parseInt(request.getParameter("seq")); %> <!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>Insert title here</title> </head> <body> <% BoardDao boardDao = new BoardDao(); boolean result = boardDao.deleteBoard(seq); /* if (result) System.out.println("삭제성공"); else System.out.println("삭제실패");*/ %> <script> alert('<%=result == true ? "삭제성공" : "삭제실패" %>'); location.href='<%=result == true ? "list.jsp" : "javascript:history.back();" %>'; </script> </body> </html>
BoardDao에 deleteBoard구현
public boolean deleteBoard(int seq){ String sql = "DELETE FROM board " + "WHERE seq = ? "; boolean result = false; try { getConnection(); st = cn.prepareStatement(sql); st.setInt(1, seq); if(st.executeUpdate() > 0) result = true; } catch (SQLException e) { e.printStackTrace(); } finally { dbClose(); } return result; }