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

📄 empbean.java

📁 完整的JAVA工程
💻 JAVA
字号:
package employee;

import java.util.*;
import java.sql.*;
import javax.swing.*;

/**
 * 有关职工信息数据库操作的类
 */
public class EmpBean {
	String sql;
	ResultSet rs = null;
	
	String eEid;
	String eName;
	String eSex;
	String eNation;
	String eRegion;
	String eEducation;
	String eSpecialty;
	String eBirthday;
	String eGstatus;
	String eMarriage;
	String eIdcard;
	String eHlocation;
	String eCityhk;
	String eCaddress;
	String ePostcode;
	String eMobilephone;
	String eHomephone;
	String eEmail;

	String colName;//列名
	String colValue;//列值

	/**
	 * 添加职工信息
	 */	
	public void empAdd(String eid,String ename, String sex, String nation, String region, String education, String specialty, String birthday, String gstatus,String marriage,String idcard, String hlocation, String cityhk, String caddress, String postcode, String mobilephone, String homephone, String email){
		
		Database DB = new Database();
		
		this.eEid = eid;
		this.eName = ename;
		this.eSex = sex;
		this.eNation = nation;
		this.eRegion = region;
		this.eEducation = education;
		this.eSpecialty = specialty;
		this.eBirthday = birthday;
		this.eGstatus = gstatus;
		this.eMarriage = marriage;
		this.eIdcard = idcard;
		this.eHlocation = hlocation;
		this.eCityhk = cityhk;
		this.eCaddress = caddress;
		this.ePostcode = postcode;
		this.eMobilephone = mobilephone;
		this.eHomephone = homephone;
		this.eEmail = email;


		if(eEid == null||eEid.equals("")){
			JOptionPane.showMessageDialog(null, "请输入职工编号", "错误", JOptionPane.ERROR_MESSAGE);
			return;
		}
		else if(eName == null||eName.equals("")){
			JOptionPane.showMessageDialog(null, "请输入职工姓名", "错误", JOptionPane.ERROR_MESSAGE);
			return;
		}
		else if(eSex == null||eSex.equals("")){
			JOptionPane.showMessageDialog(null, "请输入职工性别", "错误", JOptionPane.ERROR_MESSAGE);
			return;
		}
		else{
			sql = "insert into employee (eid,ename,sex,nation,region,education,specialty,birthday,gstatus,marriage,idcard,hlocation,cityhk,caddress,postcode,mobilephone,homephone,email) values ('"+eEid+"','"+eName+"','"+eSex+"','"+eNation+"','"+eRegion+"','"+eEducation+"','"+eSpecialty+"','"+eBirthday+"','"+eGstatus+"','"+eMarriage+"','"+eIdcard+"','"+eHlocation+"','"+eCityhk+"','"+eCaddress+"','"+ePostcode+"','"+eMobilephone+"','"+eHomephone+"','"+eEmail+"')";

			try{
				DB.OpenConn();
				DB.executeUpdate(sql);
				JOptionPane.showMessageDialog(null,"成功添加一条新的纪录!");

			}
			catch(Exception e){
				System.out.println(e);
				JOptionPane.showMessageDialog(null, "保存失败", "错误", JOptionPane.ERROR_MESSAGE); 
			}
			finally {
				DB.closeStmt();
				DB.closeConn();
			}
		}
	}

	/**
	 * 修改职工信息
	 */
	public void empModify(String eid,String ename, String sex, String nation, String region, String education, String specialty, String birthday, String gstatus,String marriage,String idcard, String hlocation, String cityhk, String caddress, String postcode, String mobilephone, String homephone, String email){
		
		Database DB = new Database();
		
		this.eEid = eid;
		this.eName = ename;
		this.eSex = sex;
		this.eNation = nation;
		this.eRegion = region;
		this.eEducation = education;
		this.eSpecialty = specialty;
		this.eBirthday = birthday;
		this.eGstatus = gstatus;
		this.eMarriage = marriage;
		this.eIdcard = idcard;
		this.eHlocation = hlocation;
		this.eCityhk = cityhk;
		this.eCaddress = caddress;
		this.ePostcode = postcode;
		this.eMobilephone = mobilephone;
		this.eHomephone = homephone;
		this.eEmail = email;

		if(eName == null||eName.equals("")){
			JOptionPane.showMessageDialog(null, "请输入职工姓名", "错误", JOptionPane.ERROR_MESSAGE);
			return;
		}
		else if(eSex == null||eSex.equals("")){
			JOptionPane.showMessageDialog(null, "请输入职工性别", "错误", JOptionPane.ERROR_MESSAGE);
			return;
		}
		else{
			sql = "update employee set ename = '"+eName+"', sex = '"+eSex+"', nation = '"+eNation+"', region = '"+eRegion+"', education = '"+eEducation+"', specialty = '"+eSpecialty+"', birthday = '"+eBirthday+"',gstatus = '"+eGstatus+"', marriage = '"+eMarriage+"', idcard = '"+eIdcard+"', hlocation = '"+eHlocation+"', cityhk = '"+eCityhk+"', caddress = '"+eCaddress+"', postcode = '"+ePostcode+"', mobilephone = '"+eMobilephone+"',homephone = '"+eHomephone+"', email = '"+eEmail+"'where eid = '"+eEid+"'";
			try{
				DB.OpenConn();
				DB.executeUpdate(sql);
				JOptionPane.showMessageDialog(null,"成功修改一条新的纪录!");
			}
			catch(Exception e){
				System.out.println(e);
				JOptionPane.showMessageDialog(null, "更新失败", "错误", JOptionPane.ERROR_MESSAGE); 
			}
			finally {
				DB.closeStmt();
				DB.closeConn();
			}
		}
	}

	/**
	 * 删除职工信息
	 */
	public void empDel(String eid){
		
		Database DB = new Database();
		this.eEid = eid;
		
		sql = "delete from employee where eid = "+eEid+"";
		try{
			DB.OpenConn();
			DB.executeUpdate(sql);
			JOptionPane.showMessageDialog(null,"成功删除一条新的纪录!");
		}
		catch(Exception e){
			System.out.println(e);
			JOptionPane.showMessageDialog(null, "删除失败", "错误", JOptionPane.ERROR_MESSAGE); 
		}
		finally {
			DB.closeStmt();
			DB.closeConn();
		}
	}

	/**
	 * 根据职工编号查询职工信息
	 */
	public String[] empSearch(String eid){
		
		Database DB = new Database();
		this.eEid = eid;
		String[] s = new String[17];
		sql = "select * from employee where eid = "+eEid+"";

		try{
			DB.OpenConn();
			rs = DB.executeQuery(sql);
			if(rs.next()){
				s[0] = rs.getString("ename");
				s[1] = rs.getString("sex");
				s[2] = rs.getString("nation");
				s[3] = rs.getString("region");
				s[4] = rs.getString("education");
				s[5] = rs.getString("specialty");
				s[6] = rs.getString("birthday");
				s[7] = rs.getString("gstatus");
				s[8] = rs.getString("marriage");
				s[9] = rs.getString("idcard");
				s[10] = rs.getString("hlocation");
				s[11] = rs.getString("cityhk");
				s[12] = rs.getString("caddress");
				s[13] = rs.getString("postcode");
				s[14] = rs.getString("mobilephone");
				s[15] = rs.getString("homephone");
				s[16] = rs.getString("email");
			}
			else
				s = null;
		}
		catch(Exception e){
		}
		finally {
			DB.closeStmt();
			DB.closeConn();
		}
		return s;
	}

	/**
	 * 职工信息综合查询(按照一个条件进行查询)
	 */
	public String[][] empAllSearch(String colname,String colvalue){
		this.colName = colname;
		this.colValue = colvalue;

		Database DB = new Database();
		String[][] sn = null;
		int row = 0;
		int i = 0;

		DB.toGBK(colvalue);
		
		if(colValue == null||colValue.equals("")){
			sql = "select * from employee";
		}
		else{
			sql = "select * from employee where "+colName+" = '"+colValue+"'";
		}
		try{
			DB.OpenConn();
			rs = DB.executeQuery(sql);

			if(rs.last()){
				row = rs.getRow();
			}
			
			if(row == 0){
				sn = null;
			}
			else{
				sn = new String[row][18];
				rs.first();
				rs.previous();
				while(rs.next()){
					sn[i][0] = rs.getString("eid");
					sn[i][1] = rs.getString("ename");
					sn[i][2] = rs.getString("sex");
					sn[i][3] = rs.getString("nation");
					sn[i][4] = rs.getString("region");
					sn[i][5] = rs.getString("education");
					sn[i][6] = rs.getString("specialty");
					sn[i][7] = rs.getString("birthday");
					sn[i][8] = rs.getString("gstatus");
					sn[i][9] = rs.getString("marriage");
					sn[i][10] = rs.getString("idcard");
					sn[i][11] = rs.getString("hlocation");
					sn[i][12] = rs.getString("cityhk");
					sn[i][13] = rs.getString("caddress");
					sn[i][14] = rs.getString("postcode");
					sn[i][15] = rs.getString("mobilephone");
					sn[i][16] = rs.getString("homephone");
					sn[i][17] = rs.getString("email");
					i++;
				}
			}
		}
		catch(Exception e){
		}
		finally {
			DB.closeStmt();
			DB.closeConn();
		}
		return sn;
	}

	/**
	 * 获得employee表中的所有职工编号eid
	 */
	public String[] getAllId(){
		String[] s = null;
		int row = 0;
		int i = 0;
		Database DB = new Database();
		sql = "select eid from employee";
		
		try{
			DB.OpenConn();
			rs = DB.executeQuery(sql);
			if(rs.last()){
				row = rs.getRow();
			}

			if(row == 0){
				s = null;
			}
			else{
				s = new String[row];
				rs.first();
				rs.previous();
				while(rs.next()){
					s[i] = rs.getString(1);
					i++;
				}
			}
		}
		catch(Exception e){
			System.out.println(e);
		}
		finally {
			DB.closeStmt();
			DB.closeConn();
		}
		return s;
	}
}

⌨️ 快捷键说明

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