12.8

发布时间 2023-12-18 18:49:41作者: new菜鸟
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.*" %>
<html>
<body>
<h3>查看出差申请</h3>
<%
String id1 = (String) session.getAttribute("id1");
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/gs?useSSL=false";
String username = "root";
String password = "123456";
conn = DriverManager.getConnection(url, username, password);

// Use a prepared statement to avoid SQL injection
String query = "SELECT * FROM class1 WHERE ID = ?";
pstmt = conn.prepareStatement(query);
pstmt.setString(1, id1);
rs = pstmt.executeQuery();
%>
<table>
<tr>
<th>申请日期</th>
<th>申请事由</th>
<th>申请状态</th>
<th>审批理由</th>

</tr>
<%
while (rs.next()) {
%>
<tr>
<td><%= rs.getString("departuredate") %></td>
<td><%= rs.getString("Reason") %></td>
<td><%= rs.getString("State") %></td>
<td><%= rs.getString("Statereason") %></td>
</tr>
<%
}
%>
</table>
<%
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null) rs.close();
if (pstmt != null) pstmt.close();
if (conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
%>