⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teacherbean.java~88~

📁 基于b/s模式的jsp在线考试系统
💻 JAVA~88~
字号:
package com.gton.bean;

import java.sql.*;
import java.util.*;
import com.gton.util.DBUtil;
import com.gton.util.DBUtil;

public class TeacherBean {
    private int admin_ID;
    private String admin_Name;
    private String admin_Pwd;
    private int admin_Age;
    private int admin_Sex;
    private String admin_No;
    private String admin_Agent;
    private String admin_Mz;

    public TeacherBean() {
    }

    public int getAdmin_Age() {
        return admin_Age;
    }

    public String getAdmin_Agent() {
        return admin_Agent;
    }

    public int getAdmin_ID() {
        return admin_ID;
    }

    public String getAdmin_Mz() {
        return admin_Mz;
    }

    public String getAdmin_Name() {
        return admin_Name;
    }

    public String getAdmin_No() {
        return admin_No;
    }

    public String getAdmin_Pwd() {
        return admin_Pwd;
    }

    public int getAdmin_Sex() {
        return admin_Sex;
    }

    public void setAdmin_Sex(int admin_Sex) {
        this.admin_Sex = admin_Sex;
    }

    public void setAdmin_Pwd(String admin_Pwd) {
        this.admin_Pwd = admin_Pwd;
    }

    public void setAdmin_No(String admin_No) {
        this.admin_No = admin_No;
    }

    public void setAdmin_Name(String admin_Name) {
        this.admin_Name = admin_Name;
    }

    public void setAdmin_Mz(String admin_Mz) {
        this.admin_Mz = admin_Mz;
    }

    public void setAdmin_ID(int admin_ID) {
        this.admin_ID = admin_ID;
    }

    public void setAdmin_Agent(String admin_Agent) {
        this.admin_Agent = admin_Agent;
    }

    public void setAdmin_Age(int admin_Age) {
        this.admin_Age = admin_Age;
    }

    public ArrayList getAllTea() {
        ArrayList list = null;
        TeacherBean bean = null;
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;

        try {
            con = DBUtil.getConnection();
            String sql = "select * from Admin";
            pstmt = con.prepareStatement(sql);
            rs = pstmt.executeQuery();
            list = new ArrayList();
            while (rs.next()) {
                bean = new TeacherBean();
                bean.setAdmin_Age(rs.getInt("Admin_Age"));
                bean.setAdmin_Agent(rs.getString("Admin_Agent"));
                bean.setAdmin_ID(rs.getInt("Admin_ID"));
                bean.setAdmin_Mz(rs.getString("Admin_Mz"));
                bean.setAdmin_Name(rs.getString("Admin_Name"));
                bean.setAdmin_No(rs.getString("Admin_No"));
                bean.setAdmin_Pwd(rs.getString("Admin_Pwd"));
                bean.setAdmin_Sex(rs.getInt("Admin_Sex"));
                list.add(bean);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DBUtil.closeConnection(rs, pstmt, con);
        }
        return list;
    }

    public boolean deleteById(int id) {
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        int rowCount = 0;
        boolean flag = false;

        try {
            con = DBUtil.getConnection();
            String sql = "delete from Admin where Admin_ID=?";
            pstmt = con.prepareStatement(sql);
            pstmt.setInt(1, id);
            rowCount = pstmt.executeUpdate();
            if (rowCount > 0) {
                flag = true;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DBUtil.closeConnection(rs, pstmt, con);
        }
        return flag;
    }

    public static TeacherBean queryById(int id) {
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        TeacherBean teabean = null;

        try {
            con = DBUtil.getConnection();
            String sql = "select * from Admin where Admin_ID=?";
            pstmt = con.prepareStatement(sql);
            pstmt.setInt(1, id);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                teabean = new TeacherBean();
                teabean.setAdmin_Age(rs.getInt("Admin_Age"));
                teabean.setAdmin_Agent(rs.getString("Admin_Agent"));
                teabean.setAdmin_ID(rs.getInt("Admin_ID"));
                teabean.setAdmin_Mz(rs.getString("Admin_Mz"));
                teabean.setAdmin_Name(rs.getString("Admin_Name"));
                teabean.setAdmin_No(rs.getString("Admin_No"));
                teabean.setAdmin_Pwd(rs.getString("Admin_Pwd"));
                teabean.setAdmin_Sex(rs.getInt("Admin_Sex"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DBUtil.closeConnection(rs, pstmt, con);
        }
        return teabean;
    }

    public static boolean modify(String name, String pwd, int age,
                                 String agent, String mz, String no, int sex) {
        boolean flag = false;
        Connection con = null;
        PreparedStatement pstmt = null;
        int rowCount = 0;

        try {
            con = DBUtil.getConnection();
            String sql = "update Admin set Admin_Pwd=?,Admin_Age=?,Admin_Sex=?,Admin_No=?,Admin_Agent=?,Admin_Mz=? where Admin_Name=?";
            pstmt = con.prepareStatement(sql);
            pstmt.setString(1, pwd);
            pstmt.setInt(2, age);
            pstmt.setInt(3, sex);
            pstmt.setString(4, no);
            pstmt.setString(5, agent);
            pstmt.setString(6, mz);
            pstmt.setString(7, name);
            rowCount = pstmt.executeUpdate();
            if (rowCount > 0) {
                flag = true;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DBUtil.closeConnection(null, pstmt, con);
        }

        return flag;
    }

    public static TeacherBean queryByName(String name) {
        TeacherBean bean = null;
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;

        try {
            con = DBUtil.getConnection();
            String sql = "select * from Admin where Admin_Name=?";
            pstmt = con.prepareStatement(sql);
            pstmt.setString(1, name);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                bean = new TeacherBean();
                bean.setAdmin_Age(rs.getInt("Admin_Age"));
                bean.setAdmin_Agent(rs.getString("Admin_Agent"));
                bean.setAdmin_ID(rs.getInt("Admin_ID"));
                bean.setAdmin_Mz(rs.getString("Admin_Mz"));
                bean.setAdmin_Name(rs.getString("Admin_Name"));
                bean.setAdmin_No(rs.getString("Admin_No"));
                bean.setAdmin_Pwd(rs.getString("Admin_Pwd"));
                bean.setAdmin_Sex(rs.getInt("Admin_Sex"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DBUtil.closeConnection(rs, pstmt, con);
        }
        return bean;
    }

    public static boolean addTeacher(TeacherBean bean) {
    boolean flag = false;
    Connection con = null;
    PreparedStatement pstmt = null;
    int rowCount = 0;

    try {
        con = DBUtil.getConnection();
        String sql = "insert into Admin(admin_name,admin_pwd,admin_age,admin_sex,admin_no,admin_agent,admin_mz) values(?,?,?,?,?,?,?)";
        pstmt = con.prepareStatement(sql);
        pstmt.setString(1, bean.getUsers_Name());
        pstmt.setString(2, bean.getUsers_Pwd());
        pstmt.setInt(3, bean.getUsers_Age());
        pstmt.setInt(4, bean.getUsers_Sex());
        pstmt.setString(5, bean.getUsers_No());
        pstmt.setString(6, bean.getUsers_Agent());
        pstmt.setString(7, bean.getUsers_Mz());
        rowCount = pstmt.executeUpdate();

        if(rowCount > 0) {
            flag = true;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        DBUtil.closeConnection(null, pstmt, con);
    }

    return flag;
}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -