diff --git "a/19 \345\224\220\345\233\275\344\272\256/20230524 \344\275\234\344\270\232.md" "b/19 \345\224\220\345\233\275\344\272\256/20230524 \344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..3920361f2117076860bf4d5f0d024726b52e0a13 --- /dev/null +++ "b/19 \345\224\220\345\233\275\344\272\256/20230524 \344\275\234\344\270\232.md" @@ -0,0 +1,114 @@ +```html + + + + + 学生管理系统 + + +
+

查询学生

+ 输入你要查询的学生编号:
+ 输入你要查询的学生姓名:
+ 输入你要查询的学生性别:
+ +
+
+

添加学生

+ 输入你要添加的学生编号:
+ 输入你要添加的学生姓名:
+ 输入你要添加的学生性别:
+ +
+
+

删除学生

+ 输入你要删除的学生编号:
+ +
+
+

修改学生

+ 输入你要修改的学生编号:
+ 输入你要修改的学生姓名:
+ +
+ + +``` + +```java +package com.dao; + +import java.sql.*; + +public class Dao { + private Connection conn; + private String driver = "com.mysql.jdbc.Driver"; + private String url ="jdbc:mysql://localhost:3306/student_db?useSSL=false&useUnicode=true&charsetEnding=utf8"; + private String user="root"; + private String password="root"; + + public Dao() { + try { + Class.forName(driver); + System.out.println("驱动加载成功"); + } catch (ClassNotFoundException e) { + System.out.println("驱动加载失败!"); + throw new RuntimeException(e); + } + } + + public Connection getConn() { + try { + conn = DriverManager.getConnection(url,user,password); + System.out.println("数据库连接成功"); + } catch (SQLException e) { + System.out.println("数据库连接失败!"); + throw new RuntimeException(e); + } + return conn; + } + + public void setConn(Connection conn) { + this.conn = conn; + } +} +``` + +```java +package com.student; + +public class Student { + private int id; + private String name; + private String sex; + + public Student() { + } + + public Student(int id, String name, String sex) { + this.id = id; + this.name = name; + this.sex = sex; + } + + public void setId(int id) { + this.id = id; + } + + + public void setName(String name) { + this.name = name; + } + + public void setSex(String sex) { + this.sex = sex; + } + + @Override + public String toString() { + return "id= "+ id +" name= "+name+" sex= "+sex; + } +} +``` + +```java