掲示板の削除


掲示板を削除しました
  • キーコード
  • QnADeleteController.java
  • package com.veranda.qna.controller;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.veranda.common.controller.SuperClass;
    import com.veranda.qna.dao.QnADao;
    
    public class QnADeleteController extends SuperClass{
    
    	@Override
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		super.doGet(request, response);
    
    		int no = Integer.parseInt(request.getParameter("no"));
    
    		QnADao dao = new QnADao();
    		int cnt = -1;
    		cnt = dao.DeleteData(no);
    
    		new QnAListController().doGet(request, response);
    	}
    }
  • QnADao.java
  • public class QnADao extends SuperDao {
    	public int DeleteData(int no) {
    		String sql = " delete from qnas ";
    		sql += " where qna_no = ? ";
    
    		PreparedStatement pstmt = null;
    		int cnt = -1;
    		try {
    			if (conn == null) {
    				super.conn = super.getConnection();
    			}
    			conn.setAutoCommit(false);
    			pstmt = super.conn.prepareStatement(sql);
    
    			pstmt.setInt(1, no);
    
    			cnt = pstmt.executeUpdate();
    			conn.commit();
    		} catch (Exception e) {
    			SQLException err = (SQLException) e;
    			cnt = -err.getErrorCode();
    			e.printStackTrace();
    			try {
    				conn.rollback();
    			} catch (Exception e2) {
    				e2.printStackTrace();
    			}
    		} finally {
    			try {
    				if (pstmt != null) {
    					pstmt.close();
    				}
    				super.closeConnection();
    			} catch (Exception e2) {
    				e2.printStackTrace();
    			}
    		}
    		return cnt;
    	}
    }