게시판 삭제

김순섭·2021년 5월 24일
0

게시판 Delete


  • 주요코드
  1. 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);
	}
}


  1. 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;
	}
}

1개의 댓글

comment-user-thumbnail
2021년 6월 24일

잘 보고 가요 ~

답글 달기

관련 채용 정보