JAVA期末项目学生管理系统

在这里插入图片描述

college

package c01.s01.t09.bean;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.Time;

/**
 * 功能:
 * 作者:
 * 日期:2022年06月10日
 */
public class College {
   
    private int id;
    private String username;
    private String password;
    private String telephone;
    private Time register_time;
    private String president;
    private String name;
    private ResultSet startTime;
    private String email;

    public int getId() {
   
        return id;
    }

    public void setId(int id) {
   
        this.id = id;
    }

    public String getUsername() {
   
        return username;
    }

    public void setUsername(String username) {
   
        this.username = username;
    }

    public String getPassword() {
   
        return password;
    }

    public void setPassword(String password) {
   
        this.password = password;
    }

    public String getTelephone() {
   
        return telephone;
    }

    public void setTelephone(String telephone) {
   
        this.telephone = telephone;
    }

    public Time getRegister_time() {
    return register_time;    }

    public void setRegister_time(Time register_time) {
    this.register_time = register_time; }

    @Override
    public String toString() {
   
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", telephone='" + telephone + '\'' +
                ", registerTime=" + register_time +
                '}';
    }


    public void setPresident(String president) {
   
        this.president = president;
    }

    public String getPresident() {
   
        return president;
    }

    public void setName(String name) {
   
        this.name = name;
    }

    public void setStartTime(Date start_time) {
   

    }

    public void setEmail(String email) {
   

    }

    public void setAddress(String address) {
   

    }

    public void setProfile(String profile) {
   

    }

    public String getName() {
   
        return null;
    }

    public ResultSet getStartTime() {
   
        return startTime;
    }

    public String getEmail() {
   
        return email;
    }

    public String getProfile() {
   
        return null;
    }
}

status

package c01.s01.t09.bean;

/**
 * 功能:
 * 作者:
 * 日期:2022年06月10日
 */
public class Status {
   
    private int id;
    private String college;
    private String version;
    private String author;
    private String telephone;
    private String address;
    private String email;

    public int getId() {
   
        return id;
    }

    public void setId(int id) {
   
        this.id = id;
    }

    public String getCollege() {
   
        return college;
    }

    public void setCollege(String username) {
   
        this.college = college;
    }

    public String getVersion() {
   
        return version;
    }

    public void setVersion(String password) {
   
        this.version = version;
    }

    public String getAuthor() {
   
        return author;
    }

    public void setAuthor(String author) {
    this.author = author;}

    public String getTelephone() {
   
        return telephone;
    }

    public void setTelephone(String telephone) {
   
        this.telephone = telephone;
    }

    public String getAdress() {
   
        return address;
    }

    public void setAddress(String address) {
   
        this.address = address;
    }

    public String getEmail() {
   
        return email;
    }

    public void setEmail(String email) {
    this.email = email;    }

    @Override
    public String toString() {
   
        return "User{" +
                "id=" + id +
                ", username='" + college + '\'' +
                ", password='" + version + '\'' +
                ", telephone='" + author + '\'' +
                ", telephone='" + telephone + '\'' +
                ", telephone='" + address + '\'' +
                ", registerTime=" + email +
                '}';
    }


    public String getAddress() {
   
        return null;
    }
}

student

package c01.s01.t09.bean;

/**
 * 功能:
 * 作者:
 * 日期:2022年06月10日
 */
public class Student {
   
    private int id;
    private String name;
    private String sex;
    private int age;
    private String department;
    private String t_class ;
    private String telephone;

    public Student() {
   

    }

    public int getId() {
   
        return id;
    }

    public void setId(int id) {
   
        this.id = id;
    }

    public String getName() {
   
        return name;
    }

    public void setName(String name) {
   
        this.name = name;
    }

    public String getSex() {
    return sex ; }

    public void setSex(String sex) {
   
        this.sex = sex;
    }

    public int getAge() {
   
        return age;
    }

    public void setAge(int age) {
   
        this.age = age;
    }

    public String getDepartment() {
   
        return department;
    }

    public void setDepartment(String department) {
   
        this.department = department;
    }

    public String getT_class() {
    return t_class ; }

    public void setT_class(String t_class) {
   
        this.sex = t_class;
    }

    public String getTelephone() {
    return telephone ; }

    public void setTelephone(String telephone) {
   this.telephone = telephone;    }

    @Override
    public String toString() {
   
        return "User{" +
                "id=" + id +
                ", username='" + name + '\'' +
                ", username='" + sex + '\'' +
                ", username='" + age + '\'' +
                ", username='" + department + '\'' +
                ", username='" + t_class + '\'' +
                ", username='" + telephone + '\'' +
                '}';
    }

}

user

package c01.s01.t09.bean;

import java.util.Date;

/**
 * 功能:用户实体类
 * 作者:
 * 日期:
 */
public class User {
   
    private int id;
    private String username;
    private String password;
    private String telephone;
    private Date registerTime;

    public User() {
   

    }

    public int getId() {
   
        return id;
    }

    public void setId(int id) {
   
        this.id = id;
    }

    public String getUsername() {
   
        return username;
    }

    public void setUsername(String username) {
   
        this.username = username;
    }

    public String getPassword() {
   
        return password;
    }

    public void setPassword(String password) {
   
        this.password = password;
    }

    public String getTelephone() {
   
        return telephone;
    }

    public void setTelephone(String telephone) {
   
        this.telephone = telephone;
    }

    public Date getRegisterTime() {
   
        return registerTime;
    }

    public void setRegisterTime(Date registerTime) {
   
        this.registerTime = registerTime;
    }

    @Override
    public String toString() {
   
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", telephone='" + telephone + '\'' +
                ", registerTime=" + registerTime +
                '}';
    }


}

t09.dao.impl(CollegeDaoImpl, StatusDaoImpl, StudentDaoImpl, UserDaoImpl)

package c01.s01.t09.dao.impl;
import c01.s01.t09.bean.Status;
import c01.s01.t09.dao.StatusDao;
import c01.s01.t09.dbutils.ConnectionManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * 功能:状态数据访问接口实现类
 * 作者:
 * 日期:
 */
public class StatusDaoImpl implements StatusDao{
   
    @Override
    public Status findById(int id) {
   
        // 声明状态对象
        Status status = null;

        // 获取数据库连接对象
        Connection conn = ConnectionManager.getConnection();
        // 定义SQL字符串
        String strSQL = "select * from t_status where id = ?";
        try {
   
            // 创建预备语句对象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            // 设置占位符的值
            pstmt.setInt(1, id);
            // 执行SQL查询,返回结果集
            ResultSet rs = pstmt.executeQuery();
            // 判断结果集是否有记录
            if (rs.next()) {
   
                // 实例化状态
                status = new Status();
                // 利用当前记录字段值去设置状态对象的属性
                status.setId(rs.getInt("id"));
                status.setCollege(rs.getString("college"));
                status.setVersion(rs.getString("version"));
                status.setAuthor(rs.getString("author"));
                status.setTelephone(rs.getString("telephone"));
                status.setAddress(rs.getString("address"));
                status.setEmail(rs.getString("email"));
            }
        } catch (SQLException e) {
   
            e.printStackTrace();
        } finally {
   
            ConnectionManager.closeConnection(conn);
        }

        // 返回状态对象
        return status;
    }

    @Override
    public int update(Status status) {
   
        // 定义更新记录数
        int count = 0;

        // 获得数据库连接
        Connection conn = ConnectionManager.getConnection();
        // 定义SQL字符串
        String strSQL = "update t_status set college = ?, version = ?, author = ?,"
                + " telephone = ?, address = ?, email = ? where id = ?";
        try {
   
            // 创建预备语句对象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            // 设置占位符的值
            pstmt.setString(1, status.getCollege());
            pstmt.setString(2, status.getVersion());
            pstmt.setString(3, status.getAuthor());
            pstmt.setString(4, status.getTelephone());
            pstmt.setString(5, status.getAddress());
            pstmt.setString(6, status.getEmail());
            pstmt.setInt(7, status.getId());
            // 执行更新操作,更新记录
            count = pstmt.executeUpdate();
            // 关闭预备语句对象
            pstmt.close();
        } catch (SQLException e) {
   
            e.printStackTrace();
        } finally {
   
            ConnectionManager.closeConnection(conn);
        }

        // 返回更新记录数
        return count;
    }

}`
``

```java
package c01.s01.t09.dao.impl;
import c01.s01.t09.bean.Status;
import c01.s01.t09.dao.StatusDao;
import c01.s01.t09.dbutils.ConnectionManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * 功能:状态数据访问接口实现类
 * 作者:
 * 日期:
 */
public class StatusDaoImpl implements StatusDao{
   
    @Override
    public Status findById(int id) {
   
        // 声明状态对象
        Status status = null;

        // 获取数据库连接对象
        Connection conn = ConnectionManager.getConnection();
        // 定义SQL字符串
        String strSQL = "select * from t_status where id = ?";
        try {
   
            // 创建预备语句对象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            // 设置占位符的值
            pstmt.setInt(1, id);
            // 执行SQL查询,返回结果集
            ResultSet rs = pstmt.executeQuery();
            // 判断结果集是否有记录
            if (rs.next()) {
   
                // 实例化状态
                status = new Status();
                // 利用当前记录字段值去设置状态对象的属性
                status.setId(rs.getInt("id"));
                status.setCollege(rs.getString("college"));
                status.setVersion(rs.getString("version"));
                status.setAuthor(rs.getString("author"));
                status.setTelephone(rs.getString("telephone"));
                status.setAddress(rs.getString("address"));
                status.setEmail(rs.getString("email"));
            }
        } catch (SQLException e) {
   
            e.printStackTrace();
        } finally {
   
            ConnectionManager.closeConnection(conn);
        }

        // 返回状态对象
        return status;
    }

    @Override
    public int update(Status status) {
   
        // 定义更新记录数
        int count = 0;

        // 获得数据库连接
        Connection conn = ConnectionManager.getConnection();
        // 定义SQL字符串
        String strSQL = "update t_status set college = ?, version = ?, author = ?,"
                + " telephone = ?, address = ?, email = ? where id = ?";
        try {
   
            // 创建预备语句对象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            // 设置占位符的值
            pstmt.setString(1, status.getCollege());
            pstmt.setString(2, status.getVersion());
            pstmt.setString(3, status.getAuthor());
            pstmt.setString(4, status.getTelephone());
            pstmt.setString(5, status.getAddress());
            pstmt.setString(6, status.getEmail());
            pstmt.setInt(7, status.getId());
            // 执行更新操作,更新记录
            count = pstmt.executeUpdate();
            // 关闭预备语句对象
            pstmt.close();
        } catch (SQLException e) {
   
            e.printStackTrace();
        } finally {
   
            ConnectionManager.closeConnection(conn);
        }

        // 返回更新记录数
        return count;
    }

}
package c01.s01.t09.dao.impl;

import c01.s01.t09.bean.Student;
import c01.s01.t09.dao.StudentDao;
import c01.s01.t09.dbutils.ConnectionManager;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 * 功能:学生数据访问接口实现类
* 作者:
* 日期:
*/
public class StudentDaoImpl implements StudentDao {
   
    /**
     * 插入学生记录
     *
     * @param student
     * @return 插入记录数
     */
    @Override
    public int insert(Student student) {
   
        //定义插入记录数
        int count = 0;

        //1、获得数据库连接
        Connection conn = ConnectionManager.getConnection();
        //2、定义SQL字符串
        String strSQL = "insert into t_student (id,name,sex,age,department,class,telephone)"
                + "values(?,?,?,?,?,?,?)";
        try {
   
            // 3、创建预备语句对象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            // 4、设置占位符的值
            pstmt.setInt(1,student.getId());
            pstmt.setString(2, student.getName());
            pstmt.setString(3,student.getSex());
            pstmt.setInt(4,student.getAge());
            pstmt.setString(5,student.getDepartment());
            pstmt.setString(6,student.getT_class());
            pstmt.setString(7,student.getTelephone());
            //5、执行SQL,返回插入记录数
            count = pstmt.executeUpdate();
            //6、关闭预备语句对象
            pstmt.close();
        } catch (SQLException e) {
   
            e.printStackTrace();
        } finally {
   
            ConnectionManager.closeConnection(conn);
        }
        return count;
    }

    /**
     * 按学号删除学生记录
     *
     * @param id
     * @return 删除记录数
     */

    @Override
    public int deleteById(String id) {
   
        //定义删除记录数
        int count = 0;

        //1、获得数据库连接
        Connection conn = ConnectionManager.getConnection();
        //2、定义SQL字符串
        String strSQL = "delete from t_student where id = ?";
        try {
   
            // 3、创建预备语句对象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            // 4、设置占位符的值
            pstmt.setString(1,id);
            //5、执行SQL,返回删除记录数
            count = pstmt.executeUpdate();
            //6、关闭预备语句对象
            pstmt.close();
        } catch (SQLException e) {
   
            e.printStackTrace();
        } finally {
   
            //关闭数据库连接
            ConnectionManager.closeConnection(conn);
        }

        //返回删除记录数
        return count;
    }

    /**
     * 按班级删除学生记录
     *
     * @param clazz
     * @return 删除记录数
     */

    @Override
    public int deleteByClass(String clazz) {
   
        //定义删除记录数
        int count = 0;

        //1、获得数据库连接
        Connection conn = ConnectionManager.getConnection();
        //2、定义SQL字符串
        String strSQL = "delete from t_student where class = ?";
        try {
   
            // 3、创建预备语句对象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            // 4、设置占位符的值
            pstmt.setString(1,clazz);
            //5、执行SQL,返回删除记录数
            count = pstmt.executeUpdate();
            //6、关闭预备语句对象
            pstmt.close();
        } catch (SQLException e) {
   
            e.printStackTrace();
        } finally {
   
            //关闭数据库连接
            ConnectionManager.closeConnection(conn);
        }
        //返回删除记录数
        return count;
    }

    /**
     * 按系部删除学生记录
     *
     * @param department
     * @return 删除记录数
     */
    @Override
    public int deleteByDepartment(String department) {
   
        //定义删除记录数
        int count = 0;

        //1、获得数据库连接
        Connection conn = ConnectionManager.getConnection();
        //2、定义SQL字符串
        String strSQL = "delete from t_student where department = ?";
        try {
   
            // 3、创建预备语句对象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            // 4、设置占位符的值
            pstmt.setString(1,department);
            //5、执行SQL,返回删除记录数
            count = pstmt.executeUpdate();
            //6、关闭预备语句对象
            pstmt.close();
        } catch (SQLException e) {
   
            e.printStackTrace();
        } finally {
   
            //关闭数据库连接
            ConnectionManager.closeConnection(conn);
        }
        //返回删除记录数
        return count;
    }

    /**
     * 更新学生记录
     *
     * @param student
     * @return 更新记录数
     */
    @Override
    public int update(Student student) {
   
        //定义更新记录数
        int count = 0;

        //1、获取数据库连接
        Connection conn = ConnectionManager.getConnection();
        //2、定义SQL字符串
        String strSQL = "update t_student set name = ?,sex = ?, age = ?,"
                +"department = ?,class = ?,telephone = ? where id = ?";
        try {
   
            //3、创建预备语句对象
            PreparedStatement pstmt = conn.prepareStatement(strSQL);
            //4、设置占位符的值
            pstmt.setString(1,student.getName());
            pstmt.setString(2,student.getSex());
            pstmt.setInt(3,student.getAge());
            pstmt.setString(4,student.getDepartment());
            pstmt.setString(5,student.getT_class());
            pstmt.setString(6,student.getTelephone());
            pstmt.setInt(7
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值