Eclipse+Java+Swing+Mysql实现员工工资管理系统(下)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: Eclipse+Java+Swing+Mysql实现员工工资管理系统

MainFrame.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * MainFrame.java
 *
 * Created on 2013-6-18, 22:12:20
 */
package com.sjsq;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JOptionPane;
/**
 *
 * @author Administrator
 */
public class MainFrame extends javax.swing.JFrame {
  /** Creates new form MainFrame */
  private Toolkit tk = Toolkit.getDefaultToolkit();
  int x = tk.getScreenSize().width / 2 - 250;
  int y = tk.getScreenSize().height / 2 - 250;
  public MainFrame() {
    setTitle("工资管理系统");
    setLocation(x, y);
    initComponents();
    // this.setDefaultCloseOperation(MainFrame.DO_NOTHING_ON_CLOSE);
  }
  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated
  // Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    jColorChooser1 = new javax.swing.JColorChooser();
    jPanel1 = new javax.swing.JPanel() {
      protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Image img = Toolkit.getDefaultToolkit().getImage("src/resource/009.jpg");
        Graphics gg = g.create();
        gg.drawImage(img, 0, 0, getWidth(), getHeight(), this);
        gg.dispose();
      }
    };
    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    jMenuItem1 = new javax.swing.JMenuItem();
    jMenuItem2 = new javax.swing.JMenuItem();
    jMenuItem3 = new javax.swing.JMenuItem();
    jMenu2 = new javax.swing.JMenu();
    jMenuItem4 = new javax.swing.JMenuItem();
    jMenuItem5 = new javax.swing.JMenuItem();
    jMenuItem6 = new javax.swing.JMenuItem();
    jMenu3 = new javax.swing.JMenu();
    jMenuItem7 = new javax.swing.JMenuItem();
    jMenuItem8 = new javax.swing.JMenuItem();
    jMenuItem12 = new javax.swing.JMenuItem();
    jMenu4 = new javax.swing.JMenu();
    jMenuItem9 = new javax.swing.JMenuItem();
    jMenuItem10 = new javax.swing.JMenuItem();
    jMenuItem13 = new javax.swing.JMenuItem();
    jMenu5 = new javax.swing.JMenu();
    jMenuItem11 = new javax.swing.JMenuItem();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    jPanel1.addAncestorListener(new javax.swing.event.AncestorListener() {
      public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
      }
      public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
        jPanel1AncestorAdded(evt);
      }
      public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
      }
    });
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 637, Short.MAX_VALUE));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 365, Short.MAX_VALUE));
    jMenu1.setText("员工信息管理");
    jMenu1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenu1ActionPerformed(evt);
      }
    });
    jMenuItem1.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
    jMenuItem1.setText("添加员工信息");
    jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem1ActionPerformed(evt);
      }
    });
    jMenu1.add(jMenuItem1);
    jMenuItem2.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
    jMenuItem2.setText("修改员工信息");
    jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem2ActionPerformed(evt);
      }
    });
    jMenu1.add(jMenuItem2);
    jMenuItem3.setAccelerator(
        javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
    jMenuItem3.setText("删除员工信息");
    jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem3ActionPerformed(evt);
      }
    });
    jMenu1.add(jMenuItem3);
    jMenuBar1.add(jMenu1);
    jMenu2.setText("部门信息管理");
    jMenuItem4.setText("新增部门信息");
    jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem4ActionPerformed(evt);
      }
    });
    jMenu2.add(jMenuItem4);
    jMenuItem5.setText("修改部门信息");
    jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem5ActionPerformed(evt);
      }
    });
    jMenu2.add(jMenuItem5);
    jMenuItem6.setText("删除部门信息");
    jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem6ActionPerformed(evt);
      }
    });
    jMenu2.add(jMenuItem6);
    jMenuBar1.add(jMenu2);
    jMenu3.setText("员工工资设定");
    jMenuItem7.setText("工资设定");
    jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem7ActionPerformed(evt);
      }
    });
    jMenu3.add(jMenuItem7);
    jMenuItem8.setText("工资查询");
    jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem8ActionPerformed(evt);
      }
    });
    jMenu3.add(jMenuItem8);
    jMenuItem12.setText("工资一览表");
    jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem12ActionPerformed(evt);
      }
    });
    jMenu3.add(jMenuItem12);
    jMenuBar1.add(jMenu3);
    jMenu4.setText("系统设置");
    jMenuItem9.setText("信息统计");
    jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem9ActionPerformed(evt);
      }
    });
    jMenu4.add(jMenuItem9);
    jMenuItem10.setText("修改密码");
    jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem10ActionPerformed(evt);
      }
    });
    jMenu4.add(jMenuItem10);
    jMenuItem13.setText("添加管理员");
    jMenuItem13.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem13ActionPerformed(evt);
      }
    });
    jMenu4.add(jMenuItem13);
    jMenuBar1.add(jMenu4);
    jMenu5.setText("退出系统");
    jMenu5.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenu5ActionPerformed(evt);
      }
    });
    jMenuItem11.setText("退出本系统");
    jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem11ActionPerformed(evt);
      }
    });
    jMenu5.add(jMenuItem11);
    jMenuBar1.add(jMenu5);
    setJMenuBar(jMenuBar1);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
        jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE,
        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
        jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
    pack();
  }// </editor-fold>//GEN-END:initComponents
  private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem1ActionPerformed
    // TODO add your handling code here:
    new AddEmployee().setVisible(true);
  }// GEN-LAST:event_jMenuItem1ActionPerformed
  private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem2ActionPerformed
    // TODO add your handling code here:
    new ModifyEmployee().setVisible(true);
  }// GEN-LAST:event_jMenuItem2ActionPerformed
  private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem3ActionPerformed
    // TODO add your handling code here:
    new DeleteEmployee().setVisible(true);
  }// GEN-LAST:event_jMenuItem3ActionPerformed
  private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem4ActionPerformed
    // TODO add your handling code here:
    new AddDepartment().setVisible(true);
  }// GEN-LAST:event_jMenuItem4ActionPerformed
  private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem5ActionPerformed
    // TODO add your handling code here:
    new ModifyDepartment().setVisible(true);
  }// GEN-LAST:event_jMenuItem5ActionPerformed
  private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem6ActionPerformed
    // TODO add your handling code here:
    new DeleteDepartment().setVisible(true);
  }// GEN-LAST:event_jMenuItem6ActionPerformed
  private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem7ActionPerformed
    // TODO add your handling code here:
    new SalarySetting().setVisible(true);
  }// GEN-LAST:event_jMenuItem7ActionPerformed
  private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem8ActionPerformed
    // TODO add your handling code here:
    new SalarySearch().setVisible(true);
  }// GEN-LAST:event_jMenuItem8ActionPerformed
  private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem9ActionPerformed
    // TODO add your handling code here:
    new Statistics().setVisible(true);
  }// GEN-LAST:event_jMenuItem9ActionPerformed
  private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem10ActionPerformed
    // TODO add your handling code here:
    new ModifyPassWord().setVisible(true);
  }// GEN-LAST:event_jMenuItem10ActionPerformed
  private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem11ActionPerformed
    // TODO add your handling code here:
    int option = JOptionPane.showConfirmDialog(null, "确定要退出本系统?", "系统提示", JOptionPane.YES_NO_OPTION);
    if (option == JOptionPane.YES_OPTION)
      System.exit(0);
    else
      this.setDefaultCloseOperation(MainFrame.DO_NOTHING_ON_CLOSE);
  }// GEN-LAST:event_jMenuItem11ActionPerformed
  private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem12ActionPerformed
    // TODO add your handling code here:
    new SalaryShow().setVisible(true);
  }// GEN-LAST:event_jMenuItem12ActionPerformed
  private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem13ActionPerformed
    // TODO add your handling code here:
    new NewManager().setVisible(true);
  }// GEN-LAST:event_jMenuItem13ActionPerformed
  private void jMenu5ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenu5ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jMenu5ActionPerformed
  private void jPanel1AncestorAdded(javax.swing.event.AncestorEvent evt) {// GEN-FIRST:event_jPanel1AncestorAdded
    // TODO add your handling code here:
  }// GEN-LAST:event_jPanel1AncestorAdded
  private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenu1ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jMenu1ActionPerformed
  /**
   * @param args the command line arguments
   */
  /*
   * public static void main(String args[]) { java.awt.EventQueue.invokeLater(new
   * Runnable() { public void run() { new MainFrame().setVisible(true); } }); }
   */
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JColorChooser jColorChooser1;
  private javax.swing.JMenu jMenu1;
  private javax.swing.JMenu jMenu2;
  private javax.swing.JMenu jMenu3;
  private javax.swing.JMenu jMenu4;
  private javax.swing.JMenu jMenu5;
  private javax.swing.JMenuBar jMenuBar1;
  private javax.swing.JMenuItem jMenuItem1;
  private javax.swing.JMenuItem jMenuItem10;
  private javax.swing.JMenuItem jMenuItem11;
  private javax.swing.JMenuItem jMenuItem12;
  private javax.swing.JMenuItem jMenuItem13;
  private javax.swing.JMenuItem jMenuItem2;
  private javax.swing.JMenuItem jMenuItem3;
  private javax.swing.JMenuItem jMenuItem4;
  private javax.swing.JMenuItem jMenuItem5;
  private javax.swing.JMenuItem jMenuItem6;
  private javax.swing.JMenuItem jMenuItem7;
  private javax.swing.JMenuItem jMenuItem8;
  private javax.swing.JMenuItem jMenuItem9;
  private javax.swing.JPanel jPanel1;
  // End of variables declaration//GEN-END:variables
}

DBConn.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sjsq;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Administrator
 */
public class DBConn {
  private Connection conn = null;
  private Statement stmt = null;
  private ResultSet rs = null;
  String url = "jdbc:mysql://localhost/swing_salary_management?serverTimezone=UTC";
  String username = "root";
  String password = "admin";
  public DBConn() { // 构造方法
    try {
      Class.forName("com.mysql.cj.jdbc.Driver");
      // conn = DriverManager.getConnection(url,username,password);
    } catch (java.lang.ClassNotFoundException e) {
      System.err.println(e.getMessage());
    } // catch (SQLException ex) {
      // Logger.getLogger(DBConn.class.getName()).log(Level.SEVERE, null, ex);
      // }
  }
  public int Check(String sql) {
    // int result = 0;
    try {
      conn = DriverManager.getConnection(url, username, password);
      stmt = conn.createStatement();
      rs = stmt.executeQuery(sql);
      if (rs.next()) {
        return 1;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return 0;
  }
  public ResultSet Search(String sql) { // 建立查询
    try {
      conn = DriverManager.getConnection(url, username, password);
      stmt = conn.createStatement();
      rs = stmt.executeQuery(sql);
    } catch (SQLException ex) {
      System.err.println(ex.getMessage());
    }
    return rs;
  }
  public int Update(String sql) { // 操作数据库
    int result = 0;
    try {
      conn = DriverManager.getConnection(url, username, password);
      stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      result = stmt.executeUpdate(sql);
    } catch (SQLException ex) {
      result = 0;
    }
    return result;
  }
  /**
   * 关闭数据库连接
   */
  public void close() {
    try {
      if (rs != null) {
        rs.close();
      }
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
    try {
      if (stmt != null) {
        stmt.close();
      }
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
    try {
      if (conn != null) {
        conn.close();
      }
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }
}

AddDepartment.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * AddDepartment.java
 *
 * Created on 2013-6-22, 12:14:44
 */
package com.sjsq;
//import SQLConnection.DBConn;
import java.awt.Toolkit;
import javax.swing.JOptionPane;
/**
 *
 * @author Administrator
 */
public class AddDepartment extends javax.swing.JFrame {
  /** Creates new form AddDepartment */
  private Toolkit tk = Toolkit.getDefaultToolkit();
  int x = tk.getScreenSize().width / 2 - 100;
  int y = tk.getScreenSize().height / 2 - 100;
  public AddDepartment() {
    initComponents();
    setTitle("添加部门信息");
    setLocation(x, y);
    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  }
  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated
  // Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jTextField2 = new javax.swing.JTextField();
    jTextField3 = new javax.swing.JTextField();
    jTextField4 = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("部门信息"));
    jLabel1.setText("部门编号:");
    jLabel2.setText("部门名称:");
    jLabel3.setText("负责人:");
    jLabel4.setText("总人数:");
    jTextField1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField1ActionPerformed(evt);
      }
    });
    jTextField2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField2ActionPerformed(evt);
      }
    });
    jTextField3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField3ActionPerformed(evt);
      }
    });
    jTextField4.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField4ActionPerformed(evt);
      }
    });
    jButton1.setText("添加");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    jButton2.setText("取消");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                        javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel2)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jTextField2))
                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel3).addGap(18, 18, 18)
                    .addComponent(jTextField3)))
            .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jButton1).addGap(18, 18, 18)
                .addComponent(jButton2))
            .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel4).addGap(18, 18, 18)
                .addComponent(jTextField4)))
            .addContainerGap(16, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel2).addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3).addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4).addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1).addComponent(jButton2))
            .addContainerGap(18, Short.MAX_VALUE)));
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addGap(79, 79, 79)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(145, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addGap(22, 22, 22)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(54, Short.MAX_VALUE)));
    pack();
  }// </editor-fold>//GEN-END:initComponents
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    String strID = jTextField1.getText(); // 部门编号
    String strName = jTextField2.getText(); // 部门姓名
    String strDirector = jTextField3.getText(); // 负责人
    String strNumber = jTextField4.getText(); // 总人数
    if (strID.equals("")) {
      JOptionPane.showMessageDialog(null, "部门编号不能为空!");
    } else if (strName.equals("")) {
      JOptionPane.showMessageDialog(null, "部门名称不能为空!");
    } else if (strDirector.equals("")) {
      JOptionPane.showMessageDialog(null, "部门负责人不能为空!");
    } else {
      // int ID = Integer.parseInt(strID);
      int Number = Integer.parseInt(strNumber);
      String checksql = "select id from department where id = '" + strID + " '";
      System.out.println(checksql);
      DBConn db = new DBConn();
      if (db.Check(checksql) != 0) {
        JOptionPane.showMessageDialog(null, "该号已存在!!!");
      } else {
        String sql = "insert into department values('" + strID + "','" + strName + "','" + strDirector + "','"
            + Number + "')";
        int result = db.Update(sql);
        if (result != 0) {
          JOptionPane.showMessageDialog(null, "部门添加成功!!!");
        } else {
          JOptionPane.showMessageDialog(null, "部门添加失败,请重新添加!");
        }
      }
    }
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField3.setText("");
    jTextField4.setText("");
  }// GEN-LAST:event_jButton1ActionPerformed
  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField3.setText("");
    jTextField4.setText("");
  }// GEN-LAST:event_jButton2ActionPerformed
  private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField1ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField1ActionPerformed
  private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField2ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField2ActionPerformed
  private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField3ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField3ActionPerformed
  private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField4ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField4ActionPerformed
  /**
   * @param args the command line arguments
   * 
   *             public static void main(String args[]) {
   *             java.awt.EventQueue.invokeLater(new Runnable() { public void
   *             run() { new AddDepartment().setVisible(true); } }); }
   */
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JTextField jTextField1;
  private javax.swing.JTextField jTextField2;
  private javax.swing.JTextField jTextField3;
  private javax.swing.JTextField jTextField4;
  // End of variables declaration//GEN-END:variables
}

AddEmployee.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * SecondGUI.java
 *
 * Created on 2013-6-19, 12:49:33
 */
package com.sjsq;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author Administrator
 */
public class AddEmployee extends javax.swing.JFrame {
  /** Creates new form SecondGUI */
  private Toolkit tk = Toolkit.getDefaultToolkit();
  int x = tk.getScreenSize().width / 2 - 180;
  int y = tk.getScreenSize().height / 2 - 180;
  DefaultTableModel dm;
  DefaultComboBoxModel dcm;
  public AddEmployee() {
    initTable();
    initComboBox();
    initComponents();
    setTitle("添加员工");
    setLocation(x, y);
    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  }
//初始化表格
  private void initTable() {
    try {
      String[] head = { "工号", "姓名", "性别", "年龄", "部门", "职位", "电话", "入厂时间", "住址" };
      Object obj[][] = new Object[0][0];
      dm = new DefaultTableModel(obj, head);
      String sql = "select id,name,sex,age,department,position,phone,time,address from employee";
      DBConn db = new DBConn();
      Vector v;
      System.out.println(sql);
      ResultSet rs = db.Search(sql);
      while (rs.next()) {
        v = new Vector();
        v.add(rs.getString(1));
        v.add(rs.getString(2));
        v.add(rs.getString(3));
        v.add(rs.getString(4));
        v.add(rs.getString(5));
        v.add(rs.getString(6));
        v.add(rs.getString(7));
        v.add(rs.getString(8));
        v.add(rs.getString(9));
        dm.addRow(v);
      }
      db.close();
    } catch (SQLException ex) {
      System.out.println(ex);
    }
  }
  /// 初始化下拉列表
  private void initComboBox() {
    Vector v = new Vector();
    DBConn db = new DBConn();
    try {
      ResultSet rs = db.Search("select distinct name from department");
      while (rs.next()) {
        v.addElement(rs.getString("name")); // 添加到向量尾部,大小加1
      }
      dcm = new DefaultComboBoxModel(v);
    } catch (SQLException ex) {
      ex.printStackTrace();
    } finally {
      db.close();
    }
  }
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated
  // Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    buttonGroup1 = new javax.swing.ButtonGroup();
    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    jTextField2 = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    jRadioButton1 = new javax.swing.JRadioButton();
    jRadioButton2 = new javax.swing.JRadioButton();
    jLabel4 = new javax.swing.JLabel();
    jTextField3 = new javax.swing.JTextField();
    jLabel5 = new javax.swing.JLabel();
    jComboBox1 = new javax.swing.JComboBox();
    jLabel6 = new javax.swing.JLabel();
    jTextField4 = new javax.swing.JTextField();
    jLabel7 = new javax.swing.JLabel();
    jTextField5 = new javax.swing.JTextField();
    jLabel8 = new javax.swing.JLabel();
    jTextField6 = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jLabel9 = new javax.swing.JLabel();
    jTextField7 = new javax.swing.JTextField();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTable1 = new javax.swing.JTable();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("员工信息"));
    jLabel1.setText("工号:");
    jLabel2.setText("姓名:");
    jTextField2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField2ActionPerformed(evt);
      }
    });
    jLabel3.setText("性别:");
    buttonGroup1.add(jRadioButton1);
    jRadioButton1.setSelected(true);
    jRadioButton1.setText("男");
    buttonGroup1.add(jRadioButton2);
    jRadioButton2.setText("女");
    jLabel4.setText("年龄:");
    jTextField3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField3ActionPerformed(evt);
      }
    });
    jLabel5.setText("所属部门:");
    jComboBox1.setModel(dcm);
    jComboBox1.setToolTipText("请选择");
    jComboBox1.setBorder(javax.swing.BorderFactory.createCompoundBorder());
    jComboBox1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jComboBox1ActionPerformed(evt);
      }
    });
    jLabel6.setText("职位:");
    jTextField4.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField4ActionPerformed(evt);
      }
    });
    jLabel7.setText("联系方式:");
    jTextField5.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField5ActionPerformed(evt);
      }
    });
    jLabel8.setText("住址:");
    jTextField6.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField6ActionPerformed(evt);
      }
    });
    jButton1.setText("添加");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    jButton2.setText("取消");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    jLabel9.setText("入厂时间:");
    jTextField7.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextField7ActionPerformed(evt);
      }
    });
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jButton1)
                .addGroup(jPanel1Layout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 82,
                            javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel2)
                        .addGap(18, 18, 18).addComponent(jTextField2))
                    .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton2))
                    .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel4)
                        .addGap(18, 18, 18).addComponent(jTextField3,
                            javax.swing.GroupLayout.PREFERRED_SIZE, 80,
                            javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup().addGap(31, 31, 31)
                        .addGroup(jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(
                                        javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel5)
                                        .addComponent(jLabel6))
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(
                                        javax.swing.GroupLayout.Alignment.LEADING,
                                        false)
                                        .addComponent(jComboBox1, 0,
                                            javax.swing.GroupLayout.DEFAULT_SIZE,
                                            Short.MAX_VALUE)
                                        .addComponent(jTextField4,
                                            javax.swing.GroupLayout.DEFAULT_SIZE,
                                            80, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(
                                        javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel7)
                                        .addComponent(jLabel9))
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(
                                        javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField7,
                                            javax.swing.GroupLayout.DEFAULT_SIZE,
                                            80, Short.MAX_VALUE)
                                        .addComponent(jTextField5)))))
                    .addGroup(jPanel1Layout.createSequentialGroup().addGap(18, 18, 18)
                        .addComponent(jButton2)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57,
                    Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel8).addGap(18, 18, 18)
                .addComponent(jTextField6, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)))
            .addContainerGap()));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel5).addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel2)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel6).addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3).addComponent(jRadioButton1).addComponent(jRadioButton2)
                .addComponent(jLabel7).addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4)
                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel9).addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel8).addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1).addComponent(jButton2))
            .addContainerGap()));
    jTable1.setAutoCreateRowSorter(true);
    jTable1.setModel(dm);
    jScrollPane1.setViewportView(jTable1);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addGap(88, 88, 88).addComponent(jPanel1,
                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup().addGap(21, 21, 21).addComponent(jScrollPane1,
                javax.swing.GroupLayout.PREFERRED_SIZE, 516, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addGap(32, 32, 32)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117,
                javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    pack();
  }// </editor-fold>//GEN-END:initComponents
  // 添加事件
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    String ID = jTextField1.getText();
    String Name = jTextField2.getText();
    String sex = "男";
    if (jRadioButton2.isSelected())
      sex = "女";
    String ageStr = jTextField3.getText();
    int age = Integer.parseInt(ageStr);
    String department = (String) jComboBox1.getSelectedItem();
    String position = jTextField4.getText(); // 职位
    String phone = jTextField5.getText(); // 电话
    String time = jTextField7.getText(); // 入厂时间
    String address = jTextField6.getText();// 住址
    if (ID.equals("")) {
      JOptionPane.showMessageDialog(null, "请输入员工号");
    } else if (Name.equals("")) {
      JOptionPane.showMessageDialog(null, "请输入员工姓名");
    } else if (ageStr.equals("")) {
      JOptionPane.showMessageDialog(null, "请输入年龄");
    } else if (department.equals("")) {
      JOptionPane.showMessageDialog(null, "请输入所在部门");
    } else if (position.equals("")) {
      JOptionPane.showMessageDialog(null, "请输入员职位");
    } else if (phone.equals("")) {
      JOptionPane.showMessageDialog(null, "请输入联系电话");
    } else if (time.equals("")) {
      JOptionPane.showMessageDialog(null, "请输入入厂时间");
    } else if (address.equals("")) {
      JOptionPane.showMessageDialog(null, "请输入住址");
    } else {
      DBConn db = new DBConn();
      if (db.Check("select ID from employee where ID = '" + ID + "'") != 0) {
        JOptionPane.showMessageDialog(null, "该工号的员工已存在!!");
      } else {
        String sql = "insert into employee values('" + ID + "','" + Name + "','" + sex + "','" + age + "','"
            + department + "','" + position + "','" + phone + "','" + time + "','" + address + "')";
        System.out.println(sql);
        int result = db.Update(sql);
        if (result != 0) {
          JOptionPane.showMessageDialog(null, "添加成功!!");
          initTable();
        }
        db.close();
      }
      new AddEmployee().setVisible(true);
    }
    // this.System.exit(0);
    this.setVisible(false);
  }// GEN-LAST:event_jButton1ActionPerformed
  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField4.setText("");
    jTextField5.setText("");
    jTextField3.setText("");
    jTextField7.setText("");
    jTextField6.setText("");
  }// GEN-LAST:event_jButton2ActionPerformed
  private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField2ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField2ActionPerformed
  private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField4ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField4ActionPerformed
  private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jComboBox1ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jComboBox1ActionPerformed
  private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField5ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField5ActionPerformed
  private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField3ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField3ActionPerformed
  private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField7ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField7ActionPerformed
  private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextField6ActionPerformed
    // TODO add your handling code here:
  }// GEN-LAST:event_jTextField6ActionPerformed
  /*
   * 
   * public static void main(String args[]) { java.awt.EventQueue.invokeLater(new
   * Runnable() { public void run() { new AddEmployee().setVisible(true);
   * 
   * } }); }
   */
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.ButtonGroup buttonGroup1;
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JComboBox jComboBox1;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JRadioButton jRadioButton1;
  private javax.swing.JRadioButton jRadioButton2;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JTable jTable1;
  private javax.swing.JTextField jTextField1;
  private javax.swing.JTextField jTextField2;
  private javax.swing.JTextField jTextField3;
  private javax.swing.JTextField jTextField4;
  private javax.swing.JTextField jTextField5;
  private javax.swing.JTextField jTextField6;
  private javax.swing.JTextField jTextField7;
  // End of variables declaration//GEN-END:variables
}


四、其他


1.更多系统


JavaSwing系统系列实现


Java+Swing实现斗地主游戏


Java+Swing实现图书管理系统


Java+Swing实现医院管理系统


Java+Swing实现考试管理系统


Java+Swing实现酒店管理系统


Java+Swing实现超市管理系统


Java+Swing实现电影购票系统


Java+Swing实现仓库管理系统-1


Java+Swing实现仓库管理系统-2


Java+Swing实现进销存管理系统


Java+Swing实现自助取款机系统


Java+Swing实现通讯录管理系统


Java+Swing实现停车场管理系统


Java+Swing实现学生信息管理系统


Java+Swing实现学生宿舍管理系统


Java+Swing实现学生选课管理系统


Java+Swing实现学生成绩管理系统


Java+Swing实现学校教材管理系统


Java+Swing实现学校教务管理系统


Java+Swing实现企业人事管理系统


Java+Swing实现电子相册管理系统


Java+Swing实现超市管理系统-TXT存储数据


Java+Swing实现自助取款机系统-TXT存储数据


Java+Swing实现宠物商店管理系统-TXT存储数据


Java+JSP系统系列实现


Java+JSP实现学生图书管理系统


Java+JSP实现学生信息管理系统


Java+JSP实现用户信息管理系统


Java+Servlet系统系列实现


Java+Servlet+JSP实现航空订票系统


Java+Servlet+JSP实现新闻发布系统


Java+Servlet+JSP学生宿舍管理系统


Java+Servlet+JSP实现图书管理系统


Java+Servlet+JSP实现停车场管理系统


Java+Servlet+JSP实现房屋租赁管理系统


Java+Servlet+JSP实现学生信息管理系统


Java+Servlet+JSP实现学生选课管理系统


Java+Servlet+JSP实现宠物诊所管理系统


Java+Servlet+JSP实现学生成绩管理系统-1


Java+Servlet+JSP实现学生成绩管理系统-2


Java+SSM系统系列实现


Java+SSM+JSP实现图书管理系统


Java+SSM+JSP实现超市订单系统


Java+SSM+JSP实现网上考试系统


Java+SSM+JSP实现宠物商城系统


Java+SSM+Layui实现学生成绩管理系统


Java+SSM+Bootstrap实现学生信息管理系统


Java+SSH系统系列实现

Java+SSH+JSP实现在线考试系统


Java+SSH+JSP实现医院在线挂号系统


Java+Springboot系统系列实现

Java+Springboot+H-ui+Maven实现营销管理系统


Java+Springboot+Bootstrap+Maven实现网上商城系统


Java+Springboot+Bootstrap+Maven实现景区旅游管理系统


1.更多JavaWeb系统请关注专栏。


https://blog.csdn.net/helongqiang/category_10020130.html

https://blog.csdn.net/helongqiang/category_10020130.html


2.更多JavaSwing系统请关注专栏。


https://blog.csdn.net/helongqiang/category_6229101.html

https://blog.csdn.net/helongqiang/category_6229101.html


2.源码下载

Java+Swing+Mysql实现员工工资管理系统


3.运行项目

请点击以下链接,部署你的项目。


Eclipse如何导入JavaSwing项目超详细图文教程


Eclipse如何导入JavaSwing项目超详细视频教程


4.备注


如有侵权请联系我删除。


5.支持博主


如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!


相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3月前
|
安全 Java API
|
3月前
|
Java 网络安全 开发工具
新手入门Java。如何下载Eclipse、写出最基本的“Hello word”以及如何连接github并且上传项目。
新手入门Java。如何下载Eclipse、写出最基本的“Hello word”以及如何连接github并且上传项目。
57 0
|
4月前
|
JavaScript Java 测试技术
基于Java的人事管理系统设计和实现(源码+LW+部署讲解)
基于Java的人事管理系统设计和实现(源码+LW+部署讲解)
86 7
|
4月前
|
JavaScript Java 测试技术
基于Java的儿童福利院管理系统设计和实现(源码+LW+部署讲解)
基于Java的儿童福利院管理系统设计和实现(源码+LW+部署讲解)
92 7
|
3月前
|
SQL Java 数据库连接
【Java】Java Swing 图书管借阅管理系统(源码+论文)【独一无二】
【Java】Java Swing 图书管借阅管理系统(源码+论文)【独一无二】
138 0
|
3月前
|
存储 数据可视化 Java
【Java】Java swing 民宿管理系统 GUI(源码+可视化界面)【独一无二】
【Java】Java swing 民宿管理系统 GUI(源码+可视化界面)【独一无二】
|
4月前
|
Java 关系型数据库 MySQL
班级通讯录管理系统(Java+MySQL)
构建了一个Java Swing应用,搭配MySQL,实现班级通讯录管理。系统具备管理员登录、班级与学生信息的增删改查功能,每个班级窗口独立且自适应布局。利用GBK编码处理中文,JDBC连接数据库,优化窗口复用和代码结构,数据变更实时同步。示例截图展示详细界面。
班级通讯录管理系统(Java+MySQL)
|
4月前
|
JavaScript 前端开发 Java
Java数字化产科管理系统源码,多家医院应用案例,可直接上项目
Java开发的数字化产科管理系统,已在多家医院实施,支持直接部署。系统涵盖孕产全程,包括门诊、住院、统计和移动服务,整合高危管理、智能提醒、档案追踪等功能,与HIS等系统对接。采用前后端分离架构,Java语言,Vue前端,若依框架,MySQL数据库。优势在于提升就诊效率,降低漏检率,自动报表生成,减少重复工作,支持数据研究,并实现医院与卫计委平台的数据互通,打造全生育周期健康服务。
65 4
|
4月前
|
存储 Oracle Java
Java面试题:描述如何使用Eclipse或IntelliJ IDEA进行Java开发?
Java面试题:描述如何使用Eclipse或IntelliJ IDEA进行Java开发?
47 0
|
4月前
|
关系型数据库 MySQL 数据库连接
解决在eclipse2021中,用mysql-connector-java-8.0.18.jar不兼容,导致无法访问数据库问题
解决在eclipse2021中,用mysql-connector-java-8.0.18.jar不兼容,导致无法访问数据库问题
107 0

推荐镜像

更多