基于swing的人事管理系统

概述

个人项目人事管理系统,针对部门和人员之间的管理。

详细

一、项目UI

1.png

2.png

3.png

二、项目结构

4.png

三、项目使用方法

Eclipse导入现有现有项目到工作空间即可,会自动加载包内相关jar包,使用的java源文件

四、部分代码

MainFrm.java

package view;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
 
import java.awt.Color;
 
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
 
import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
 
import java.awt.Event;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.PrintJob;
import java.awt.Toolkit;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
import javax.swing.JTabbedPane;
 
import java.awt.CardLayout;
import java.awt.GridLayout;
import java.util.Properties;
 
import javax.swing.SwingConstants;
 
/**
 * 主窗体类
 * @author 22219
 *
 */
public class MainFrm extends JFrame {
    /**
     * 版本串号serialVersionUID
     */
    private static final long serialVersionUID = 1L;
    public static JPanel contentPane;
    private static JTextField empNoTextField;
    private static JTextField empPositionTextField;
    private static JTextField empNameTextField;
    private static JTextField empSexTextField;
    private static JTextField empAgeTextField;
    private static JTextField idNumberTextField;
    private static JTextField depNameTextField;
    private static JTextField addressTextField;
    public static String userId;
 
    private static JTabbedPane tabbedPane;
    private static PanelDepartment panelDepartment;
    private static PanelEmployee panelEmployee;
    private static JPanel empInfo;
 
    /**
     * Create the frame.
     */
    public MainFrm(String userid) {
        userId = userid;
        setIconImage(Toolkit.getDefaultToolkit().getImage(
                MainFrm.class.getResource("/images/storage_128px.png")));
        setTitle("人事管理系统");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setBounds(100, 100, 1600, 800);
        contentPane = new JPanel();
        contentPane.setBackground(Color.WHITE);
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(new BorderLayout(0, 0));
 
        JMenuBar menuBar = new JMenuBar();
        contentPane.add(menuBar, BorderLayout.NORTH);
        menuBar.setBackground(Color.WHITE);
 
        // 文件
        JMenu mnNewMenu = new JMenu("文件");
        mnNewMenu.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/base.png")));
        menuBar.add(mnNewMenu);
 
        // 文件->注销
        JMenuItem logoutMenuItem = new JMenuItem("注销");
        logoutMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        logoutMenuItem.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/password.png")));
        mnNewMenu.add(logoutMenuItem);
        logoutMenuItem.setMnemonic(KeyEvent.VK_A);
        logoutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,
                Event.CTRL_MASK));
        logoutMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (JOptionPane.showConfirmDialog(null, "确认注销?", "提示",
                        JOptionPane.YES_NO_OPTION) == 0) {
                    dispose();
                    LogOnFrm frame = new LogOnFrm();
                    frame.setVisible(true);
                     
                }
            }
        });
 
        // 文件->退出
        JMenuItem mntmNewMenuItem_2 = new JMenuItem("退出");
        mntmNewMenuItem_2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        mntmNewMenuItem_2.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/exit.png")));
        mnNewMenu.add(mntmNewMenuItem_2);
        mntmNewMenuItem_2.setMnemonic(KeyEvent.VK_Q);
        mntmNewMenuItem_2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
                Event.CTRL_MASK));
        mntmNewMenuItem_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (JOptionPane.showConfirmDialog(null, "确认退出?", "提示",
                        JOptionPane.YES_NO_OPTION) == 0) {
                    System.exit(0);
                }
            }
        });
 
        // 功能
        JMenu mnNewMenu_3 = new JMenu("功能");
        mnNewMenu_3.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/bookTypeManager.png")));
        menuBar.add(mnNewMenu_3);
 
        // 功能->部门管理
        JMenuItem mntmNewMenuItem_1 = new JMenuItem("部门管理");
        mntmNewMenuItem_1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        mntmNewMenuItem_1.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/bookTypeManager.png")));
        mnNewMenu_3.add(mntmNewMenuItem_1);
        mntmNewMenuItem_1.setMnemonic(KeyEvent.VK_F2);
        mntmNewMenuItem_1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2,
                0));
        mntmNewMenuItem_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                tabbedPane.setSelectedComponent(panelDepartment);
            }
        });
 
        // 功能->员工管理
        JMenuItem mntmNewMenuItem_3 = new JMenuItem("员工管理");
        mntmNewMenuItem_3.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        mntmNewMenuItem_3.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/userName.png")));
        mnNewMenu_3.add(mntmNewMenuItem_3);
        mntmNewMenuItem_3.setMnemonic(KeyEvent.VK_F3);
        mntmNewMenuItem_3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3,
                0));
        mntmNewMenuItem_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                tabbedPane.setSelectedComponent(panelEmployee);
            }
        });
 
        // 功能->人员信息
        JMenuItem mntmNewMenuItem_4 = new JMenuItem("人员信息");
        mntmNewMenuItem_4.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        mntmNewMenuItem_4.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/userName.png")));
        mnNewMenu_3.add(mntmNewMenuItem_4);
        mntmNewMenuItem_4.setMnemonic(KeyEvent.VK_F4);
        mntmNewMenuItem_4.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,
                0));
        mntmNewMenuItem_4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                tabbedPane.setSelectedComponent(empInfo);
            }
        });
 
        // 主题切换
        JMenu viewMenu = new JMenu("主题");
        viewMenu.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/view.png")));
        menuBar.add(viewMenu);
        ButtonGroup group = new ButtonGroup();
        JRadioButtonMenuItem v1 = new JRadioButtonMenuItem("Metal", true);
        v1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        v1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/edit.png")));
        viewMenu.add(v1);
        v1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    UIManager
                            .setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
                    SwingUtilities.updateComponentTreeUI(MainFrm.this);
                } catch (ClassNotFoundException | InstantiationException
                        | IllegalAccessException
                        | UnsupportedLookAndFeelException e1) {
                }
            }
        });
        JRadioButtonMenuItem v2 = new JRadioButtonMenuItem("Motif");
        v2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        v2.setIcon(new ImageIcon(MainFrm.class.getResource("/images/edit.png")));
        viewMenu.add(v2);
        v2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    UIManager
                            .setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
                    SwingUtilities.updateComponentTreeUI(MainFrm.this);
                } catch (ClassNotFoundException | InstantiationException
                        | IllegalAccessException
                        | UnsupportedLookAndFeelException e1) {
                }
            }
        });
        JRadioButtonMenuItem v3 = new JRadioButtonMenuItem("Windows");
        v3.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        v3.setIcon(new ImageIcon(MainFrm.class.getResource("/images/edit.png")));
        viewMenu.add(v3);
        v3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    UIManager
                            .setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                    SwingUtilities.updateComponentTreeUI(MainFrm.this);
                } catch (ClassNotFoundException | InstantiationException
                        | IllegalAccessException
                        | UnsupportedLookAndFeelException e1) {
                }
            }
        });
        JRadioButtonMenuItem v4 = new JRadioButtonMenuItem("Nimbus");
        v4.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        v4.setIcon(new ImageIcon(MainFrm.class.getResource("/images/edit.png")));
        viewMenu.add(v4);
        v4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    UIManager
                            .setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
                    SwingUtilities.updateComponentTreeUI(MainFrm.this);
                } catch (ClassNotFoundException | InstantiationException
                        | IllegalAccessException
                        | UnsupportedLookAndFeelException e1) {
                }
            }
        });
        JRadioButtonMenuItem v5 = new JRadioButtonMenuItem("beautyeye");
        v5.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        v5.setIcon(new ImageIcon(MainFrm.class.getResource("/images/edit.png")));
        viewMenu.add(v5);
        v5.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.generalNoTranslucencyShadow;
                    org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper
                            .launchBeautyEyeLNF();
                    UIManager.put("RootPane.setupButtonVisible", false);
                    SwingUtilities.updateComponentTreeUI(MainFrm.this);
                } catch (Exception e1) {
                }
            }
        });
        group.add(v1);
        group.add(v2);
        group.add(v3);
        group.add(v4);
        group.add(v5);
        viewMenu.add(v1);
        viewMenu.add(v2);
        viewMenu.add(v3);
        viewMenu.add(v4);
        viewMenu.add(v5);
 
        // 关于
        JMenu mnNewMenu_4 = new JMenu("关于");
        mnNewMenu_4.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/about.png")));
        menuBar.add(mnNewMenu_4);
 
        // 关于->帮助
        JMenuItem mntmNewMenuItem = new JMenuItem("帮助");
        mntmNewMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        mntmNewMenuItem.setIcon(new ImageIcon(MainFrm.class
                .getResource("/images/me.png")));
        mnNewMenu_4.add(mntmNewMenuItem);
        mntmNewMenuItem.setMnemonic(KeyEvent.VK_F1);
        mntmNewMenuItem.setAccelerator(KeyStroke
                .getKeyStroke(KeyEvent.VK_F1, 0));
        mntmNewMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(MainFrm.this, "人事管理系统:\n"
                        + "在企业中,人事管理工作是非常重要的一项工作,它负责整个企业的日常人事安排,\n"
                        + "人员的人事管理等。高效的人事管理可以提高企业的市场竞争力,使企业具有更强的凝\n" + "聚力和活力。"
                        + "", "关于", 1);
            }
        });
 
        // 添加管理板块选项卡面板(PanelDep+PanelEmp+empInfo)
        tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        contentPane.add(tabbedPane, BorderLayout.CENTER);
 
        panelDepartment = new PanelDepartment("empsal", "dep");
        panelDepartment.setBorder(new EmptyBorder(5, 5, 5, 5));
        panelEmployee = new PanelEmployee("empsal", "emp");
        panelEmployee.setBorder(new EmptyBorder(5, 5, 5, 5));
        empInfo = new JPanel();
        empInfo.setBorder(new EmptyBorder(5, 5, 5, 5));
        empInfo.setLayout(new BorderLayout(0, 0));
        tabbedPane.addTab("部门管理", null, panelDepartment, null);
        tabbedPane.addTab("员工管理", null, panelEmployee, null);
        tabbedPane.addTab("人员信息", null, empInfo, null);
 
        // 个人信息选项卡
        JToolBar toolBar = new JToolBar();
        empInfo.add(toolBar, BorderLayout.NORTH);
 
        JButton btnNewButton = new JButton("\u4E0A\u4E00\u4E2A");
        btnNewButton.setIcon(new ImageIcon(EmpInfo.class
                .getResource("/images/NavBack.png")));
        toolBar.add(btnNewButton);
 
        JButton btnNewButton_1 = new JButton("\u4E0B\u4E00\u4E2A");
        btnNewButton_1.setIcon(new ImageIcon(EmpInfo.class
                .getResource("/images/NavForward.png")));
        toolBar.add(btnNewButton_1);
 
        JButton btnNewButton_5 = new JButton("\u589E\u52A0");
        btnNewButton_5.setIcon(new ImageIcon(EmpInfo.class
                .getResource("/images/add.png")));
        toolBar.add(btnNewButton_5);
 
        JButton btnNewButton_2 = new JButton("\u5BFC\u51FA");
        btnNewButton_2.setIcon(new ImageIcon(EmpInfo.class
                .getResource("/images/saveHS.png")));
        toolBar.add(btnNewButton_2);
 
        JButton btnNewButton_3 = new JButton("\u6253\u5370");
        btnNewButton_3.setIcon(new ImageIcon(EmpInfo.class
                .getResource("/images/PrintHS.png")));
        toolBar.add(btnNewButton_3);
 
        JButton btnNewButton_4 = new JButton("\u9000\u51FA");
        btnNewButton_4.setIcon(new ImageIcon(EmpInfo.class
                .getResource("/images/RestartHS.png")));
        toolBar.add(btnNewButton_4);
 
        JTabbedPane tabbedPane1 = new JTabbedPane(JTabbedPane.TOP);
        empInfo.add(tabbedPane1, BorderLayout.CENTER);
 
        JPanel fatherBaseInfoPanel = new JPanel();
        fatherBaseInfoPanel.setLayout(new BorderLayout());
        JPanel baseInfoPanel = new JPanel();
        fatherBaseInfoPanel.add(baseInfoPanel, BorderLayout.CENTER);
 
        tabbedPane1.addTab("基本信息", null, fatherBaseInfoPanel, null);
        baseInfoPanel.setLayout(new GridLayout(5, 4, 200, 100));
 
        JLabel empNoLabel = new JLabel("\u5458\u5DE5ID");
        empNoLabel.setHorizontalAlignment(SwingConstants.CENTER);
        baseInfoPanel.add(empNoLabel);
 
        empNoTextField = new JTextField();
        baseInfoPanel.add(empNoTextField);
        empNoTextField.setColumns(10);
 
        JLabel empNameLabel = new JLabel("\u59D3\u540D");
        empNameLabel.setHorizontalAlignment(SwingConstants.CENTER);
        baseInfoPanel.add(empNameLabel);
 
        empNameTextField = new JTextField();
        empNameTextField.setColumns(10);
        baseInfoPanel.add(empNameTextField);
 
        JLabel empAgeLabel = new JLabel("\u5E74\u9F84");
        empAgeLabel.setHorizontalAlignment(SwingConstants.CENTER);
        baseInfoPanel.add(empAgeLabel);
 
        empAgeTextField = new JTextField();
        empAgeTextField.setColumns(10);
        baseInfoPanel.add(empAgeTextField);
 
        JLabel empSexLabel = new JLabel("\u6027\u522B");
        empSexLabel.setHorizontalAlignment(SwingConstants.CENTER);
        baseInfoPanel.add(empSexLabel);
 
        empSexTextField = new JTextField();
        empSexTextField.setColumns(10);
        baseInfoPanel.add(empSexTextField);
 
        JLabel idNumberLabel = new JLabel("\u8EAB\u4EFD\u8BC1\u53F7");
        idNumberLabel.setHorizontalAlignment(SwingConstants.CENTER);
        baseInfoPanel.add(idNumberLabel);
 
        idNumberTextField = new JTextField();
        idNumberTextField.setColumns(10);
        baseInfoPanel.add(idNumberTextField);
 
        JLabel empPositionLabel = new JLabel("\u804C\u52A1");
        empPositionLabel.setHorizontalAlignment(SwingConstants.CENTER);
        baseInfoPanel.add(empPositionLabel);
 
        empPositionTextField = new JTextField();
        empPositionTextField.setColumns(10);
        baseInfoPanel.add(empPositionTextField);
 
        JLabel lblNewLabel_2 = new JLabel("\u6240\u5C5E\u90E8\u95E8");
        lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
        baseInfoPanel.add(lblNewLabel_2);
 
        depNameTextField = new JTextField();
        depNameTextField.setColumns(10);
        baseInfoPanel.add(depNameTextField);
 
        JLabel addressLabel = new JLabel("\u5C45\u4F4F\u5730");
        addressLabel.setHorizontalAlignment(SwingConstants.CENTER);
        baseInfoPanel.add(addressLabel);
 
        addressTextField = new JTextField();
        addressTextField.setColumns(10);
        baseInfoPanel.add(addressTextField);
 
        JLabel lblNewLabel_3 = new JLabel(
                "     \u53CC\u51FB\u9009\u62E9\u7167\u7247");
        lblNewLabel_3.setBackground(Color.WHITE);
        fatherBaseInfoPanel.add(lblNewLabel_3, BorderLayout.EAST);
        lblNewLabel_3.setBorder(BorderFactory.createLineBorder(Color.black));
 
        JPanel panel_1 = new JPanel();
        tabbedPane1.addTab("社会关系", null, panel_1, null);
        panel_1.setLayout(null);
 
        JPanel panel_2 = new JPanel();
        tabbedPane1.addTab("工资晋升", null, panel_2, null);
        panel_2.setLayout(null);
 
        JPanel panel_3 = new JPanel();
        tabbedPane1.addTab("待开发", null, panel_3, null);
 
        JPanel panel_4 = new JPanel();
        tabbedPane1.addTab("待开发", null, panel_4, null);
 
        // 按钮监听
        addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
                int code = e.getKeyCode();
                if (code == KeyEvent.VK_F5) {
                }
            }
 
        });
 
        // 关闭窗口监听
        this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                if (JOptionPane.showConfirmDialog(null, "确认退出?", "提示",
                        JOptionPane.YES_NO_OPTION) == 0) {
                    System.exit(0);
                }
 
            }
        });
    }
 
 
    /**
     * 测试主窗口
     */
    public static void main(String[] args) {
        // try{
        // BeautyEyeLNFHelper.frameBorderStyle =
        // BeautyEyeLNFHelper.FrameBorderStyle.generalNoTranslucencyShadow;
        // org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
        // }catch(Exception e){}
        // UIManager.put("RootPane.setupButtonVisible", false);
        MainFrm frame = new MainFrm("NULL");
        frame.setVisible(true);
//      frame.printFrameAction();
    }
}

EmployeeDao.java
package dao;
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
import javax.swing.JOptionPane;
 
import util.DbUtil;
import view.MainFrm;
import model.Employee;
 
/**
 * 员工Dao类
 * 实现Employee的添、删、改、查数据库操作类EmployeeDao
 * @author 22219
 *
 */   
public class EmployeeDao {
 
    private EmployeeDao() {}
 
    /**
     * 添加员工
     * @param e
     */
    public static void addEmployee(Employee e) {
        Connection conn = null;
        try {
            conn = DbUtil.getCon();
            PreparedStatement ps = conn
                    .prepareStatement("INSERT INTO emp (empNo,empName,depName,empPosition,empSex,empAge,idNumber,address) VALUES (?,?,?,?,?,?,?,?)");
            ps.setString(1, e.getEmpNo());
            ps.setString(2, e.getEmpName());
            ps.setString(3, e.getDepName());
            ps.setString(4, e.getEmpPosition());
            ps.setString(5, e.getEmpSex());
            ps.setString(6, e.getEmpAge());
            ps.setString(7, e.getIdNumber());
            ps.setString(8, e.getAddress());
             
            ps.executeUpdate();
            ps.close();
        } catch (Exception ex) { 
            JOptionPane.showMessageDialog(MainFrm.contentPane,
                    "插入出错,请检查:\n1.员工id是否重复输入!\n2.部门名是否拼写错误!");
        } finally {
            DbUtil.closeCon(conn);
        }
    }
 
    /**
     * 删除员工
     * @param id
     */
    public static void deleteEmployee(String id) {
        Connection conn = null;
        try {
            conn = DbUtil.getCon();
            PreparedStatement ps = conn
                    .prepareStatement("DELETE FROM emp WHERE empNo=?");
            ps.setString(1, id);
            ps.executeUpdate();
            ps.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DbUtil.closeCon(conn);
        }
    }
 
    /**
     * 修改员工信息
     * @param a
     */
    public static void updateEmployee(Employee a) {
        Connection conn = null;
        try {
            conn = DbUtil.getCon();
            String Sql = "UPDATE emp SET empNo=?,empName=?,depName=?,empPosition=?,empSex=?,empAge=?,idNumber=?,address=? WHERE empNo =?";
            PreparedStatement ps = conn.prepareStatement(Sql);
            ps.setString(1, a.getEmpNo());
            ps.setString(2, a.getEmpName());
            ps.setString(3, a.getDepName());
            ps.setString(4, a.getEmpPosition());
            ps.setString(5, a.getEmpSex());
            ps.setString(6, a.getEmpAge());
            ps.setString(7, a.getIdNumber());
            ps.setString(8, a.getAddress());
            ps.setString(9, a.getEmpNo());
 
            ps.executeUpdate();
            ps.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DbUtil.closeCon(conn);
        }
    }
 
    /**
     * 根据员工号empNo查询
     * @param id
     * @return
     */
    public static Employee getEmployee(String id) {
        Employee e = null;
        Connection conn = null;
        try {
            conn = DbUtil.getCon();
            // 建立PreparedStatement对象用于预编译SQL语句
            PreparedStatement ps = conn
                    .prepareStatement("SELECT * FROM emp WHERE empno=?");
            ps.setString(1, id);
            ResultSet rs = ps.executeQuery(); // 执行查询,返回结果集
            if (rs.next()) { // 因为管理员id是惟一的,所以只返回一个结果既可
                e = new Employee(rs.getString(1), rs.getString(2),
                        rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8));
            }
            ps.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DbUtil.closeCon(conn);
        }
        return e;
    }
 
    // 查询表中的所有记录(员工),返回迭代器对象
    public static Iterator<Employee> getAllEmployee() {
        List<Employee> l = new ArrayList<Employee>();// 数组列表类对象,大小可自动增加
        Connection conn = null;
        try {
            conn = DbUtil.getCon(); // 获得数据连接
            Statement stmt = conn.createStatement(); // 建立Statement用于执行SQL操作
            ResultSet rs = stmt.executeQuery("SELECT * FROM emp");// 执行查询,返回结果集
            while (rs.next()) {// 循环得到所有记录,并添加到数组列表中
                l.add(new Employee(rs.getString(1), rs.getString(2),
                        rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8)));
            }
            stmt.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            DbUtil.closeCon(conn);
        }
        return l.iterator();// 返回迭代器对象
    }
 
    /*
     * 主程序测试功能
     */
    public static void main(String[] args) {
//      Employee admin = new Employee();
//      EmployeeDao.addEmployee(admin);
        for (Iterator<Employee> it = EmployeeDao.getAllEmployee(); it.hasNext();) {
            Employee a1 = (Employee) it.next();
            System.out.println(a1.getEmpNo() + "\t" + a1.getEmpName() + "\t"
                    + a1.getDepName());
        }
    }
 
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/123983.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Docker指定容器使用内存

Docker指定容器使用内存 作者&#xff1a;铁乐与猫 如果是还没有生成的容器&#xff0c;你可以从指定镜像生成容器时特意加上 run -m 256m 或 --memory-swap512m来限制。 -m操作指定的是物理内存&#xff0c;还有虚拟交换分区默认也会生成同样的大小&#xff0c;而–memory-…

ubuntu系统黑屏,且光标不闪烁

选择第二个&#xff0c;进入恢复模式 选择第二个&#xff0c;进入恢复模式 选择root 输入&#xff1a; startx然后就可以进入文本界面或者图形化界面了&#xff0c;如果不行&#xff0c;报错&#xff0c;可能需要需要下载这个包&#xff0c;把这个错误到网上搜索一下就可以找…

批量迁移redis实例的key

我们知道migrate 命令可以迁移redis的多个key&#xff0c;但是如果redis的key有非常多&#xff0c;那用起来就很不方便了。 所以下面分享一个脚本来实现批量key的迁移&#xff0c;主要使用的命令为dump和restore 脚本如下&#xff1a; #!/bin/bash redis-cli -h host1 -p 63…

Redis被攻击纪实

一、前言 声明&#xff1a;本文仅供技术交流使用&#xff0c;严禁采用本文的方法进行任何非法活动。 上周新来的同事分享Redis的原理和机制&#xff0c;想起2017年的时候测试环境Redis被攻击&#xff0c;最后只能重新安装服务器&#xff0c;今天试验一把利用Redis漏洞进行攻击…

成集云 | 英克对接零售O2O+线上商城 | 解决方案

方案介绍 零售O2O线上商城是一种新型的商业模式&#xff0c;它通过线上和线下的融合&#xff0c;提供更加便捷的购物体验。其中&#xff0c;O2O指的是线上与线下的结合&#xff0c;通过互联网平台与实体店面的结合&#xff0c;实现线上线下的互动和协同。线上商城则是指通过互…

AI优秀企业案例——机器人流程自动化:达观数据RPA

通过学习业内领先公司的最佳实践&#xff0c;我们可以更好地将它们应用到我们自己的公司和业务中。特别是第三部分&#xff0c;提供了大量应用案例&#xff0c;让我们一起期待看到这些案例的结尾。 1.简介 达观数据是一家专注于智能文本机器人的国家高新技术企业&#xff0c;…

Leetcode-面试题 02.02 返回倒数第 k 个节点

快慢指针&#xff1a;让快指针先移动n个节点&#xff0c;之后快慢指针一起依次向后移动一个结点&#xff0c;等到快指针移动到链表尾时&#xff0c;慢指针则移动到倒数第n个结点位置。 /*** Definition for singly-linked list.* public class ListNode {* int val;* …

矩阵等价和向量组等价的一些问题

什么是向量组&#xff1f;答&#xff1a;向量组是由若干同维数的列向量&#xff08;或同维数的行向量&#xff09;组成的集合。什么是向量组等价&#xff1f;答&#xff1a;两个向量组&#xff0c;各自拼成矩阵A和B&#xff0c;向量组等价就是三秩相等&#xff0c;即r&#xff…

点信息标注_BillboardTextActor3D

开发环境&#xff1a; Windows 11 家庭中文版Microsoft Visual Studio Community 2019VTK-9.3.0.rc0vtk-example参考代码 demo解决问题&#xff1a;点附近创建左边或其他信息&#xff0c;且信息面板显示状态不受相机缩放、旋转影响 prj name: BillboardTextActor3D #include…

STM32笔记—定时器

目录 一、TIM简介 二、基本定时器&#xff08;TIM6和TIM7&#xff09; 1. TIM6和TIM7简介 2. TIM6和TIM7的主要特性 3. TIM6和TIM7的功能 3.1 时基单元 3.2 计数模式 3.3 时钟源 三、通用定时器 1. TIMx(2、3、4、5)简介 2. TIMx主要功能 3. 时钟选择 4. 影子寄存…

计算机视觉驾驶行为识别应用简述

一、什么是计算机视觉识别&#xff1f; 计算机视觉识别是一种基于图像处理和机器学习的人工智能应用技术&#xff0c;可以用于多个场景。常见应用场景包括人脸识别、场景识别、OCR识别以及商品识别等。今天以咱们国产系统豌豆云为例&#xff0c;为大家梳理一下在车辆驾驶行为中…

在Google Kubernetes集群创建分布式Jenkins(二)

上一篇博客在Google Kubernetes集群创建分布式Jenkins(一)-CSDN博客我介绍了如何在GCP的K8S集群上部署一个分布式的Jenkins&#xff0c;并实现了一个简单的Pipeline的运行。 在实际的开发中&#xff0c;我们通常都会按照以下的CICD流程来设置Pipeline 在我司的实际实践中&…

如何让群晖Audio Station公开共享的本地音频公网可访问?

文章目录 1. 本教程使用环境&#xff1a;2. 制作音频分享链接3. 制作永久固定音频分享链接&#xff1a; 之前文章我详细介绍了如何在公网环境下使用pc和移动端访问群晖Audio Station&#xff1a; 公网访问群晖audiostation听歌 - cpolar 极点云 群晖套件不仅能读写本地文件&a…

9.spark自适应查询-AQE之动态调整Join策略

目录 概述动态调整Join策略原理实战 动态优化倾斜的 Join原理实战 概述 broadcast hash join 类似于 Spark 共享变量中的广播变量&#xff0c;Spark join 如果能采取这种策略&#xff0c;那join 的性能是最好的 自适应查询AQE(Adaptive Query Execution) 动态调整Join策略 原…

vue 子页面通过暴露属性,实现主页面的某事件的触发

目录 1.前言2.代码2-1 子页面2-2 主页面 1.前言 需求&#xff1a;当我在子页面定义了一个定时器&#xff0c;点击获取验证码&#xff0c;计时器开始倒计时&#xff0c;在这个定时器没有走完&#xff0c;退出关闭子页面&#xff0c;再次进入子页面&#xff0c;定时器此时会被刷…

linux基础:3.linux基础环境开发工具和配置。

linux基础环境开发工具和配置 一.学习yum工具进行软件安装&#xff1a;1.什么是yum&#xff1a;2.查看软件包&#xff1a;3.安装和删除&#xff1a;4.yum生态&#xff1a; 二.vim的使用&#xff1a;一.快速介绍一下vim二.vim正常模式&#xff1a;2-1&#xff1a;命令模式1.光标…

1、C语言面向对象引入类和对象的概念

什么是类和对象 类 类是用户自定义的一种数据类型&#xff0c;也称类类型——C语言中的结构体 对象 类的一种具象 代码测试 #include <stdio.h>//类 struct Animal{ char name[12];//成员属性 int age; char sex; void (*peat)();//成员方法 void (*pbeat)(); };void…

【排序算法】 快速排序(快排)!图解+实现详解!

&#x1f3a5; 屿小夏 &#xff1a; 个人主页 &#x1f525;个人专栏 &#xff1a; 算法—排序篇 &#x1f304; 莫道桑榆晚&#xff0c;为霞尚满天&#xff01; 文章目录 &#x1f4d1;前言&#x1f324;️快速排序的概念☁️快速排序的由来☁️快速排序的思想☁️快速排序的实…

C++打怪升级(十)- STL之vector

~~~~ 前言1. vector 是什么2. 见见vector的常用接口函数吧构造函数无参构造函数使用n个val构造拷贝构造使用迭代器范围构造初始化形参列表构造 析构函数赋值运算符重载函数元素访问[]运算符重载函数访问at函数访问front函数back函数 迭代器相关正向迭代器反向迭代器 容量相关si…

Head First Java 第二版

不管你的程序有多大&#xff0c;一定都会有一个main()来作为程序的起点。Java是强类型语言。float f23.5f 如果不加上f&#xff0c;就会被Java当做double处理。对于任意一个Java虚拟机来说&#xff0c;所有的引用大小都一样&#xff0c;但是不同的Java虚拟机可能会以不同的方…