学生基本信息管理

一.团队介绍

201921123067徐亦菲(组长)
主要工作:创建数据库,实现修改,删除,查找的功能
201921123068郝冰冰
主要工作:GUI界面设计,实现添加查看的功能

二.项目Git地址

https://gitee.com/hao-bingbing/java-code

三.Git提交记录截图

四.项目功能架构图

五.项目运行截图








六.关键代码

添加学生信息

public boolean addStu(Student student) {
		Connection connection = DbUtil.getConnection();// 获得数据库连接对象
		String sql = "INSERT INTO student(number,name,sex,birthday,politicalStatus,homeAddress,phone,dormitoryNum)values(?,?,?,?,?,?,?,?)";
		try {
			PreparedStatement ps = connection.prepareStatement(sql);
			ps.setString(1, student.getNumber());
			ps.setString(2, student.getName());
			ps.setString(3, student.getSex());
			ps.setString(4, student.getBirthday());
			ps.setString(5, student.getPoliticalStatus());
			ps.setString(6, student.getHomeAddress());
			ps.setString(7, student.getPhone());
			ps.setString(8, student.getDormitoryNum());
			if (!ps.execute()) {
				DbUtil.close(connection, ps);// 关闭连接
				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;// 失败
	}

删除学生信息

public boolean delStu(String number) {
		Connection connection = DbUtil.getConnection();
		String sql = "delete from student where number=?";

		try {
			PreparedStatement ps = connection.prepareStatement(sql);
			ps.setString(1, number);
			if (!ps.execute()) {// 删除成功
				DbUtil.close(connection, ps);// 关闭连接
				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

查找学生信息

public Student findStu(String number) {
		Connection connection = DbUtil.getConnection();
		String sql = "SELECT number,name,sex,birthday,politicalStatus,homeAddress,phone,dormitoryNum FROM student where number=?";
		try {
			PreparedStatement ps = connection.prepareStatement(sql);
			ps.setString(1, number);
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {// 存在学生,封装返回
				Student student = new Student(rs.getString("number"), rs.getString("name"), rs.getString("sex"),
						rs.getString("birthday"),rs.getString("politicalStatus"),rs.getString("homeAddress"),rs.getString("phone"),rs.getString("dormitoryNum"));
				DbUtil.close(connection, ps);// 关闭连接
				return student;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;// 没有学生
	}

修改学生信息

public boolean updateStu(Student student) {
		Connection connection = DbUtil.getConnection();// 获得数据库连接对象
		String sql = "update student set name=?,sex=?,birthday=?,politicalStatus=?,homeAddress=?,phone=?,dormitoryNum=? where number=?";
		try {
			PreparedStatement ps = connection.prepareStatement(sql);
			ps.setString(1, student.getName());
			ps.setString(2, student.getSex());
			ps.setString(3, student.getBirthday());
			ps.setString(4, student.getPoliticalStatus());
			ps.setString(5, student.getHomeAddress());
			ps.setString(6, student.getPhone());
			ps.setString(7, student.getDormitoryNum());
			ps.setString(8, student.getNumber());
			if (!ps.execute()) {
				DbUtil.close(connection, ps);// 关闭连接
				return true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;// 失败
	}

七.尚待改进的地方

界面不够美观,实现功能较少且只能根据学号进行删除修改等操作,过于局限

posted @ 2021-01-29 09:44  h_hhh  阅读(158)  评论(0编辑  收藏  举报