diff --git a/KNU_MUSEUM/src/main/webapp/admin_artifact.jsp b/KNU_MUSEUM/src/main/webapp/admin_artifact.jsp index b9bb9d9..2bda523 100644 --- a/KNU_MUSEUM/src/main/webapp/admin_artifact.jsp +++ b/KNU_MUSEUM/src/main/webapp/admin_artifact.jsp @@ -72,12 +72,6 @@ aria-current="page" href="admin_artifact.jsp">유물 리스트 - - -
diff --git a/KNU_MUSEUM/src/main/webapp/artifact_edit.jsp b/KNU_MUSEUM/src/main/webapp/artifact_edit.jsp index 5d842ed..156586b 100644 --- a/KNU_MUSEUM/src/main/webapp/artifact_edit.jsp +++ b/KNU_MUSEUM/src/main/webapp/artifact_edit.jsp @@ -7,7 +7,7 @@ KNU_MUSEUM - + -
-
+ + <% + // Get the ArtifactID from the request parameter + String ArtifactID = request.getParameter("ArtifactID"); + + // Declare variables to store retrieved details + String Artname = ""; + String Image = ""; + String Location = ""; + String Class = ""; + String Era = ""; + String MadminID = ""; + + // Check if ArtifactID is not null + if (ArtifactID != null && !ArtifactID.isEmpty()) { + try { + // Prepare SQL statement to retrieve details for the given ArtifactID + String query = "SELECT Artname, Image, Location, Class, Era, MadminID FROM Artifact WHERE ArtifactID = ?"; + PreparedStatement pstmt = conn.prepareStatement(query); + pstmt.setString(1, ArtifactID); + + // Execute the query + ResultSet rs = pstmt.executeQuery(); + + // Check if the result set has a row + if (rs.next()) { + // Retrieve details + Artname = rs.getString("Artname"); + Image = rs.getString("Image"); + Location = rs.getString("Location"); + Class = rs.getString("Class"); + Era = rs.getString("Era"); + MadminID = rs.getString("MadminID"); + } + + // Close resources + rs.close(); + pstmt.close(); + } catch (Exception e) { + // Handle exceptions + e.printStackTrace(); + } + } else { + // Handle the case where ArtifactID is null or empty + out.println("ArtifactID is not specified."); + } + %> +

기존 정보

+ placeholder="유물이름" name="artifact_name" value="<%=Artname%>" + readonly> +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +

수정 정보

+
+ +
+
+ name="nartifact_picture">
-
@@ -100,7 +182,7 @@
- @@ -130,50 +212,12 @@
+ + + +
-<% - String query = new String(); - PreparedStatement pstmt; - ResultSet rs; - query = "select Count(1) from Artifact"; - pstmt = conn.prepareStatement(query); - rs = pstmt.executeQuery(); - request.setCharacterEncoding("utf-8"); - int row = 0; - if(rs.next()) - row = rs.getInt(1); - String cnt = Integer.toString(row+1); - String aID = "A" + cnt; - String aName = request.getParameter("artifact_name"); - String aPicture = request.getParameter("artifact_picture"); - String aClass = request.getParameter("artifact_class"); - String aLocation = request.getParameter("artifact_location"); - String aEra = request.getParameter("artifact_era"); - String MadminID; - if (aLocation == null) { - MadminID = "admin662"; - } else if (aLocation.equals("제2전시실")) { - MadminID = "admin168"; - } else if (aLocation.equals("제3전시실")) { - MadminID = "admin239"; - } else if (aLocation.equals("제4전시실")) { - MadminID = "admin131"; - } else if (aLocation.equals("제5전시실")) { - MadminID = "admin870"; - } else { - MadminID = "admin662"; - } - query = "Insert Into Artifact Values ('" + aID + "' ,'" + aName + "', '" + aPicture + "' , '" + aClass + "' , '" + aLocation + "' , '" + aEra + "' , '" + MadminID + "')"; - out.println(query); - //insert가 계속 안됨 -> 해결 필요!! -%> - -<% - rs.close(); - pstmt.close(); - conn.close(); -%> \ No newline at end of file diff --git a/KNU_MUSEUM/src/main/webapp/artifact_edit_complete.jsp b/KNU_MUSEUM/src/main/webapp/artifact_edit_complete.jsp new file mode 100644 index 0000000..f93f5be --- /dev/null +++ b/KNU_MUSEUM/src/main/webapp/artifact_edit_complete.jsp @@ -0,0 +1,108 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ page language="java" import="java.text.*, java.sql.*"%> +<%@ page import="common.Person"%> + + + + +KNU_MUSEUM + + + + + + <% + 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; + Statement stmt = null; + Class.forName("oracle.jdbc.driver.OracleDriver"); + conn = DriverManager.getConnection(url, user, pass); + request.setCharacterEncoding("utf-8"); + + String AdminID = (String) session.getAttribute("AdminID"); + + String ArtifactID = request.getParameter("ArtifactID"); + + String Artname = request.getParameter("artifact_name"); + String Image = request.getParameter("artifact_picture"); + String Location = request.getParameter("artifact_location"); + String Class = request.getParameter("artifact_class"); + String Era = request.getParameter("artifact_era"); + + String MadminID = request.getParameter("MadminID"); + + String nArtname = request.getParameter("nartifact_name"); + String nImage = request.getParameter("nartifact_picture"); + String nLocation = request.getParameter("nartifact_location"); + String nClass = request.getParameter("nartifact_class"); + String nEra = request.getParameter("nartifact_era"); + String nMadminID = ""; + + if (nLocation == null) { + nMadminID = "admin662"; + } else if (nLocation.equals("제2전시실")) { + nMadminID = "admin168"; + } else if (nLocation.equals("제3전시실")) { + nMadminID = "admin239"; + } else if (nLocation.equals("제4전시실")) { + nMadminID = "admin131"; + } else if (nLocation.equals("제5전시실")) { + nMadminID = "admin870"; + } else { + nMadminID = "admin662"; + } + %> + + <% + String sql = "UPDATE ARTIFACT SET Artname = ?, Image = ?, Location = ?, Class = ?, Era = ?, MadminID = ? WHERE ArtifactID = ?"; + PreparedStatement updateArtifact = conn.prepareStatement(sql); + + try { + if (nArtname != null && !nArtname.isEmpty()) { + updateArtifact.setString(1, nArtname); + updateArtifact.setString(2, nImage); + updateArtifact.setString(3, nLocation); + updateArtifact.setString(4, nClass); + updateArtifact.setString(5, nEra); + updateArtifact.setString(6, nMadminID); + updateArtifact.setString(7, ArtifactID); + + // Execute the update + int res = updateArtifact.executeUpdate(); + + if (res > 0) { + response.sendRedirect("admin_artifact.jsp"); + } else { + // Handle the case where the update was not successful + out.println("Update failed."); + } + } + } catch (SQLException e) { + // Handle SQL exception (print or log the details) + e.printStackTrace(); + } finally { + // Close resources in a finally block + try { + if (updateArtifact != null) { + updateArtifact.close(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + %> + %> + + + \ No newline at end of file