• 学生基本信息管理


    一.团队介绍

    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;// 失败
    	}
    
    

    七.尚待改进的地方

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

  • 相关阅读:
    c++ ShellExecuteEx调用java打包的exe程序
    麻省理工学院公开课-第四讲:快速排序 及 随机化 算法
    Win10的IIS与以前版本的一个区别
    干就行了!!!写程序就像珊瑚,分支太多,哪有那么多复用!
    NPoco的使用方法
    为什么前端要写标准代码?
    对于委托、事件、观察者模式最一目了然的代码段
    delphi处理消息的几种方式
    哎呀妈呀,吓死我了,幸好服务器没崩溃。
    Delphi的Hint介绍以及用其重写气泡提示以达到好看的效果
  • 原文地址:https://www.cnblogs.com/123123-/p/14342847.html
Copyright © 2020-2023  润新知