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();
}
}
}