博客摘录「 以太网链路层帧格式分析实验 -Ethereal」2023年5月28日

Ethernet II 协议中的source(Src)是表示源地址,Dstination(Dst)表示目的地址。

https://nair.wenwen7.com/c.html

public SelectData() {
    // 连接数据库
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
    } catch (Exception e) {
        // TODO: handle exception
    }
    String urlString = "jdbc:mysql://localhost:3306/students?useSSL=false&serverTimezone=UTC";
    String userString = "root";
    String passwordString = "";// 根据自己数据库的密码填写
    try {
        con = DriverManager.getConnection(urlString, userString, passwordString);
    } catch (SQLException e) {
        // TODO: handle exception
        System.out.println(e);
    }
}

public ArrayList<Student> SelectModel(String keyword) {
    ArrayList<Student> list = new ArrayList<Student>();
    String sqlSelect = "select * from student where 学号 like '%"+ keyword + "%' or 姓名 like '%"+ keyword + "%'";
    try {
        presql = con.prepareStatement(sqlSelect);
        rs = presql.executeQuery();
        while (rs.next()) {
            int num=rs.getInt(1);
            String name=rs.getString(2);
            double score=rs.getDouble(3);
            Student stu=new Student(num,name,score);
            list.add(stu);
        }
        con.close();
    } catch (SQLException e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return list;
}

import java.sql.*;

public class StudentManagementSystem {
    private static final String url = "jdbc:mysql://localhost:3306/student_db?useSSL=false";
    private static final String user = "root";
    private static final String password = "password";

    public static void main(String[] args) {
        try {
            Connection conn = DriverManager.getConnection(url, user, password);
            System.out.println("数据库已连接");

            // 查询所有学生信息
            PreparedStatement stmt = conn.prepareStatement("SELECT * FROM student");
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getInt(1) + ", " + rs.getString(2) + ", " + rs.getString(3) + ", " + rs.getInt(4) + ", " + rs.getString(5) + ", " + rs.getInt(6));
            }

            // 添加学生信息
            stmt = conn.prepareStatement("INSERT INTO student (name, gender, age, phone, class_id) VALUES (?, ?, ?, ?, ?)");
            stmt.setString(1, "张三");
            stmt.setString(2, "男");
            stmt.setInt(3, 20);
            stmt.setString(4, "123456789");
            stmt.setInt(5, 1);
            stmt.executeUpdate();

            // 更新学生信息
            stmt = conn.prepareStatement("UPDATE student SET name = ?, age = ? WHERE id = ?");
            stmt.setString(1, "李四");
            stmt.setInt(2, 22);
            stmt.setInt(3, 1);
            stmt.executeUpdate();

            // 删除学生信息
            stmt = conn.prepareStatement("DELETE FROM student WHERE id = ?");
            stmt.setInt(1, 1);
            stmt.executeUpdate();

            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值