写了点极限测试
package com.example.limittest01; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @WebServlet("/processApprove") public class ProcessApproveServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // 获取表单提交的数据 String employeeId = request.getParameter("employeeId"); String attendanceType = request.getParameter("attendanceType"); String approvedType = request.getParameter("approvedType"); try { // 建立数据库连接 Connection connection = DatabaseConnection.getConnection(); // 查询是否存在符合条件的记录 String query = "SELECT * FROM attendance WHERE JobID = ? AND AttendanceType = ? AND ApprovedType = ?"; PreparedStatement preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, employeeId); preparedStatement.setString(2, attendanceType); preparedStatement.setString(3, approvedType); ResultSet resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { // 符合条件的记录存在,更新approvedType String updateQuery = "UPDATE attendance SET ApprovedType = ? WHERE JobID = ?"; preparedStatement = connection.prepareStatement(updateQuery); preparedStatement.setInt(1, 1); // 将approvedType改为1表示批准 preparedStatement.setString(2, employeeId); int rowsAffected = preparedStatement.executeUpdate(); if (rowsAffected > 0) { out.println("<h3>批准成功</h3>"); } else { out.println("<h3>批准失败</h3>"); } } else { out.println("<h3>用户没有请假申请或用户不存在</h3>"); } preparedStatement.close(); connection.close(); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); } } }