From 4fed92cf433329d04164ee975d8f91119bcf66ae Mon Sep 17 00:00:00 2001 From: mouse4432 Date: Tue, 5 Dec 2023 20:29:23 +0900 Subject: [PATCH] transaction#1 fixing --- .../main/webapp/program_apply_complete.jsp | 142 +++++++++++++++++- .../src/main/webapp/program_apply_fail.jsp | 60 ++++++++ 2 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 KNU_MUSEUM/src/main/webapp/program_apply_fail.jsp diff --git a/KNU_MUSEUM/src/main/webapp/program_apply_complete.jsp b/KNU_MUSEUM/src/main/webapp/program_apply_complete.jsp index da6db6e..bd19bed 100644 --- a/KNU_MUSEUM/src/main/webapp/program_apply_complete.jsp +++ b/KNU_MUSEUM/src/main/webapp/program_apply_complete.jsp @@ -17,6 +17,124 @@ crossorigin="anonymous"> + <% + String serverIP = "localhost"; + //String strSID = "xe"; + String strSID = "orcl"; + String portNum = "1521"; + String user = "KNU_MUSEUM"; + String pass = "comp322"; + String url = "jdbc:oracle:thin:@" + serverIP + ":" + portNum + ":" + strSID; + Connection conn = null; + PreparedStatement pstmt = null; + ResultSet rs; + Statement stmt = null; + + Class.forName("oracle.jdbc.driver.OracleDriver"); + conn = DriverManager.getConnection(url, user, pass); + conn.setAutoCommit(false); + stmt = conn.createStatement(); + + request.setCharacterEncoding("utf-8"); + + String UserID = (String) session.getAttribute("UserID"); + String CeduID = request.getParameter("program"); + String ApplyNum = request.getParameter("num"); + String MAppDate = request.getParameter("selectedDate"); + String MAppTimeS = request.getParameter("time"); + String CuserID = UserID; + String title = ""; + + // CeduID 설정 + if (request.getSession().getAttribute("selectedEduID") != null) { + CeduID = (String) request.getSession().getAttribute("selectedEduID"); + } + + try { + conn.setAutoCommit(false); + + // Check if the program still exists + String programCheckQuery = "SELECT COUNT(*) FROM MUSEUM_PROGRAM_LIST WHERE EduID = ?"; + PreparedStatement programCheckStmt = conn.prepareStatement(programCheckQuery); + programCheckStmt.setString(1, CeduID); + ResultSet programCheckResult = programCheckStmt.executeQuery(); + programCheckResult.next(); + int programCount = programCheckResult.getInt(1); + programCheckStmt.close(); + programCheckResult.close(); + + if (programCount == 0) { + // The program does not exist, redirect to program_apply.jsp + response.sendRedirect("program_apply_fail.jsp"); + } else { + // ApplyID 설정 + String maxApplyIDQuery = "SELECT MAX(TO_NUMBER(SUBSTR(ApplyID, 6))) AS MaxApplyID FROM MUSEUM_PROGRAM_APPLICATION"; + ResultSet maxApplyIDResultSet = stmt.executeQuery(maxApplyIDQuery); + maxApplyIDResultSet.next(); + int maxApplyIDNumber = maxApplyIDResultSet.getInt(1); + int newApplyIDNumber = maxApplyIDNumber + 1; + String newApplyID = "apply" + newApplyIDNumber; + maxApplyIDResultSet.close(); + + // 해당 프로그램에 맞는 CadminID 가져오기 + String sql2 = "SELECT MadminID FROM MUSEUM_PROGRAM_LIST WHERE EduID = ?"; + PreparedStatement pstmt3 = conn.prepareStatement(sql2); + pstmt3.setString(1, CeduID); + ResultSet adminIDResultSet = pstmt3.executeQuery(); + String CadminID = null; + if (adminIDResultSet.next()) { + CadminID = adminIDResultSet.getString(1); + } else { + // Handle the case when no matching EduID is found + out.println("No matching EduID found in the museum_program_list table."); + } + pstmt3.close(); + adminIDResultSet.close(); + + String sql = "INSERT INTO MUSEUM_PROGRAM_APPLICATION (ApplyID, ApplyNum, MAppDate, MAppTime, Status, CeduID, CuserID, CadminID) VALUES (?, ?, TO_DATE(?, 'YYYY.MM.DD'), ?, ?, ?, ?, ?)"; + PreparedStatement pstmt2 = conn.prepareStatement(sql); + pstmt2.setString(1, newApplyID); + pstmt2.setInt(2, Integer.parseInt(ApplyNum)); + pstmt2.setString(3, MAppDate); + pstmt2.setInt(4, Integer.parseInt(MAppTimeS)); + pstmt2.setInt(5, 2); // Status 0: 반려, Status 1: 승인, Status 2: 대기 + pstmt2.setString(6, CeduID); + pstmt2.setString(7, CuserID); + pstmt2.setString(8, CadminID); + + int res = pstmt2.executeUpdate(); + pstmt2.close(); + + String sql1 = "select title from museum_program_list where eduid = ?"; + PreparedStatement pstmt1 = conn.prepareStatement(sql1); + pstmt1.setString(1, CeduID); + ResultSet rs1 = pstmt1.executeQuery(); + if (rs1.next()) { + title = rs1.getString(1); + } else { + out.println("No matching title found in the museum_program_list table."); + } + conn.commit(); + } + } catch (SQLException e) { + e.printStackTrace(); + conn.rollback(); + } finally { + try { + if (pstmt != null) { + pstmt.close(); + } + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + %>
-

신청에 실패했습니다.

-

다시 신청하러 가기

+

신청이 완료되었습니다.

+ + + + + + + + + + + + + + + + + +
프로그램 제목신청 날짜신청 시간신청 인원
<%=title%><%=MAppDate%><%=MAppTimeS%><%=ApplyNum%>
+

신청내역 확인하기

diff --git a/KNU_MUSEUM/src/main/webapp/program_apply_fail.jsp b/KNU_MUSEUM/src/main/webapp/program_apply_fail.jsp new file mode 100644 index 0000000..da6db6e --- /dev/null +++ b/KNU_MUSEUM/src/main/webapp/program_apply_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