diff --git a/KNU_MUSEUM/src/main/webapp/program_apply_manage_fail.jsp b/KNU_MUSEUM/src/main/webapp/program_apply_manage_fail.jsp new file mode 100644 index 0000000..27dadb6 --- /dev/null +++ b/KNU_MUSEUM/src/main/webapp/program_apply_manage_fail.jsp @@ -0,0 +1,60 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ page language="java" + import="java.text.*, java.sql.*, java.time.LocalDate"%> +<%@ page import="common.Person"%> + + + + +KNU_MUSEUM + + + + + + + + +
+

회원이 프로그램 신청을 취소했습니다.

+

다시 체험 프로그램 신청서 체크하기

+
+ + + + + \ No newline at end of file diff --git a/KNU_MUSEUM/src/main/webapp/program_apply_o.jsp b/KNU_MUSEUM/src/main/webapp/program_apply_o.jsp index 5f1c98b..2a9cf8f 100644 --- a/KNU_MUSEUM/src/main/webapp/program_apply_o.jsp +++ b/KNU_MUSEUM/src/main/webapp/program_apply_o.jsp @@ -66,46 +66,54 @@ - <% - String ApplyID = request.getParameter("ApplyID"); - - String query = "UPDATE MUSEUM_PROGRAM_APPLICATION SET Status = '1' WHERE ApplyID = ?"; + <% PreparedStatement pstmt = null; try { conn.setAutoCommit(false); - pstmt = conn.prepareStatement(query); - pstmt.setString(1, ApplyID); + String ApplyID = request.getParameter("ApplyID"); + // Check if the application still exists + String applicationCheckQuery = "SELECT COUNT(*) FROM MUSEUM_PROGRAM_APPLICATION WHERE ApplyID = ?"; + PreparedStatement applicationCheckStmt = conn.prepareStatement(applicationCheckQuery); + applicationCheckStmt.setString(1, ApplyID); + ResultSet applicationCheckResult = applicationCheckStmt.executeQuery(); + applicationCheckResult.next(); + int applicationCount = applicationCheckResult.getInt(1); + applicationCheckStmt.close(); + applicationCheckResult.close(); + if (applicationCount == 0) { + response.sendRedirect("program_apply_manage_fail.jsp"); + } else { + String query = "UPDATE MUSEUM_PROGRAM_APPLICATION SET Status = '1' WHERE ApplyID = ?"; + pstmt = conn.prepareStatement(query); + pstmt.setString(1, ApplyID); - // executeUpdate 메서드를 사용하여 업데이트된 행 수를 반환 - int rowsUpdated = pstmt.executeUpdate(); + int rowsUpdated = pstmt.executeUpdate(); + + out.println("
"); + if (rowsUpdated > 0) { + out.println("업데이트 성공"); + conn.commit(); + } else { + out.println("업데이트된 행이 없음"); + conn.rollback(); + } + out.println("관리 페이지로 돌아가기"); + out.println("
"); + } - out.println("
"); - if (rowsUpdated > 0) { - out.println("업데이트 성공"); - conn.commit(); - } else { - out.println("업데이트된 행이 없음"); - conn.rollback(); - } - out.println("관리 페이지로 돌아가기"); - out.println("
"); - } catch (SQLException e) { - e.printStackTrace(); + e.printStackTrace(); } finally { - // 리소스 해제 - try { - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - e.printStackTrace(); - } + // 리소스 해제 + try { + if (pstmt != null) { + pstmt.close(); } - - %> - - + } catch (SQLException e) { + e.printStackTrace(); + } + } + %> \ No newline at end of file diff --git a/KNU_MUSEUM/src/main/webapp/program_apply_x.jsp b/KNU_MUSEUM/src/main/webapp/program_apply_x.jsp index 13814ac..7ea1044 100644 --- a/KNU_MUSEUM/src/main/webapp/program_apply_x.jsp +++ b/KNU_MUSEUM/src/main/webapp/program_apply_x.jsp @@ -68,11 +68,24 @@ <% String ApplyID = request.getParameter("ApplyID"); - String query = "UPDATE MUSEUM_PROGRAM_APPLICATION SET Status = '0' WHERE ApplyID = ?"; + PreparedStatement pstmt = null; try { conn.setAutoCommit(false); + // Check if the application still exists + String applicationCheckQuery = "SELECT COUNT(*) FROM MUSEUM_PROGRAM_APPLICATION WHERE ApplyID = ?"; + PreparedStatement applicationCheckStmt = conn.prepareStatement(applicationCheckQuery); + applicationCheckStmt.setString(1, ApplyID); + ResultSet applicationCheckResult = applicationCheckStmt.executeQuery(); + applicationCheckResult.next(); + int applicationCount = applicationCheckResult.getInt(1); + applicationCheckStmt.close(); + applicationCheckResult.close(); + if (applicationCount == 0) { + response.sendRedirect("program_apply_manage_fail.jsp"); + } else{ + String query = "UPDATE MUSEUM_PROGRAM_APPLICATION SET Status = '0' WHERE ApplyID = ?"; pstmt = conn.prepareStatement(query); pstmt.setString(1, ApplyID); @@ -89,6 +102,7 @@ } out.println("관리 페이지로 돌아가기"); out.println(""); + } } catch (SQLException e) { e.printStackTrace(); } finally { @@ -101,7 +115,6 @@ e.printStackTrace(); } } - %>