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

📄 emp.java

📁 这是《Struts开发入门与项目实践》的源代码
💻 JAVA
字号:
package StudyNote;

import java.util.*;
import java.sql.Connection;
import java.sql.ResultSet;

public class Emp {  
	private int id = 0;	
	private String name = null;	
	private String sex = null;	
	private String birthday = null;	
	private String degree = null;
	private String dep = null;	
	private String duty = null;	
	private String tel = null;	
	private String exp = null;
	private int depId = 0;	
	
	 
	public Emp(){}
	
	public void setId(int id) {
		this.id = id;
	}
	  
	public int getId() {
		return id;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	  
	public String getName() {
		return name;
	}
	  

	public void setSex(String sex) {
		this.sex = sex;
	}
	  
	public String getSex() {
		return sex;
	}
	
	public void setDegree(String degree) {
		this.degree = degree;
	}
	  
	public String getDegree() {
		return degree;
	}
	
	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}
	  
	public String getBirthday() {
		return birthday;
	}
	
	public void setDep(String dep) {
		this.dep = dep;
	}
	  
	public String getDep() {
		return dep;
	}
	
	public void setTel(String tel) {
		this.tel = tel;
	}
	  
	public String getTel() {
		return tel;
	}
	
	public void setDuty(String duty) {
		this.duty = duty;
	}
	  
	public String getDuty() {
		return duty;
	}
	
	public void setExp(String exp) {
		this.exp = exp;
	}
	  
	public String getExp() {
		return exp;
	}
	
	public void setDepId(int depId) {
		this.depId = depId;
	}
	  
	public int getDepId() {
		return depId;
	}
	
	public boolean Insert(DB db) throws Exception{
        String strSql;
		ResultSet rs;
		int iMaxId;
        strSql = "Select max(id) From emp";
		rs = db.OpenSql(strSql);  
		if ( rs.next()) {
			iMaxId=rs.getInt(1)+1;
		}
		else{
			iMaxId=1;
		}
		
        strSql = "insert into emp values(" 
        		+ iMaxId 	+",'"
				+ name 	+"','"
				+ sex 		+"','"
				+ birthday 	+"','"
				+ tel 	+"',"
        		+ depId 	+",'"
				+ duty 	+"','"
				+ degree +"','"
				+ exp +"')";
		if ( db.ExecSql(strSql)==0) {
			return false;
		}
		else{
			return true;
		}
	}
		
	public static Vector Search(DB db ,int depId,String empName) throws Exception{
		Vector EmpList = new Vector();
		ResultSet rs,rsNest;
        String strSql=null;
		
        
        if (depId==0){
        	strSql = "select distinct emp.id,emp.name,emp.sex,emp.duty,emp.telephone,dep.depname "
        		+ " from emp,dep where emp.depid=dep.id and emp.name like '%" + empName + "%'";
        	
        }
        else{
        	strSql = "select distinct emp.id,emp.name,emp.sex,emp.duty,emp.telephone,dep.depname "
        		+ " from emp,dep where emp.depid=dep.id and emp.depid="+depId+" and emp.name like '%" + empName + "%'";
        }
		rs = db.OpenSql(strSql);
		
		while  (rs.next()){
			Emp emp = new Emp();
			
			emp.setId(rs.getInt("id")) ;
			emp.setName(rs.getString("name")) ;
			emp.setSex(rs.getString("sex")) ;
			emp.setDuty(rs.getString("duty")) ;
			emp.setTel(rs.getString("telephone")) ;
			emp.setDep(rs.getString("depname")) ;
			
			EmpList.add(emp);
		}
		return EmpList;
	}
	

	public static boolean Delete(DB db,int empId) throws Exception{
        String strSql;
        strSql = "delete from emp where id="+empId;
		if ( db.ExecSql(strSql)==0) {
			return false;
		}
		else{
			return true;
		}
	}
		
}

⌨️ 快捷键说明

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