每日总结5.12

实际上我自己已经很久没有写每日总结了,今天突然想把这个拾起来,就又开始了

从课程来说今天还是照常的接近满课,下午的web实验的实验三的主要内容是做一个简单的增删改查,下面附上部分代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%
    // 连接数据库
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cssystem", "root", "150372");
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT * FROM stu");
    } catch (Exception e) {
        response.sendRedirect("error.jsp");
    }
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Database Management System</h1>
    <table border="1">
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Sex</th>
            <th>Birthday</th>
            <th>Action</th>
        </tr>
        <% while(rs.next()) { %>
            <tr>
                <td><%= rs.getInt("id") %></td>
                <td><%= rs.getString("name") %></td>
                <td><%= rs.getString("sex") %></td>
                <td><%= rs.getString("birthday") %></td>
                <td>
                    <a href="edit.jsp?id=<%= rs.getInt("id") %>">Edit</a>
                    <a href="del.jsp?id=<%= rs.getInt("id") %>">Delete</a>
                </td>
            </tr>
        <% } %>
    </table>
    <br>
    <a href="add.jsp">添加学生</a>
</body>
</html>
<%
    // 关闭数据库连接
    try {
        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
        if (conn != null) conn.close();
    } catch (Exception e) {}
%>

 

posted on 2023-05-12 17:52  wardream  阅读(19)  评论(0)    收藏  举报