12.11

发布时间 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 class2 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("returndate") %></td>
<td><%= rs.getString("Reason") %></td>
<td><%= rs.getString("schedule") %></td>
<td><%= rs.getString("schedulereason") %></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();
}
}
%>