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

📄 employeebean.java

📁 是jsp开发与应用详解的全部源代码
💻 JAVA
字号:
package com.jspdev.ch18;
import com.jspdev.util.*;
import java.sql.*;
import javax.sql.*;
import java.io.*;
import java.util.*;
public class EmployeeBean
{
	private   Connection conn ;
	public EmployeeBean()throws Exception
	{
		this.conn=DatabaseConn.getConnection();
	}
	public void addEmployee(Employee employee)throws Exception
	{
	     this.executeHelper("insert into employee values('"+employee.getId()+"','"+employee.getName()+"',"+employee.getSalary()+",'"+employee.getDepartment()+"',"+employee.getAge()+")");
	}
	public Collection getEmployees()throws Exception
	{
		return this.getEmployeeHelper("select * from Employee");
	 }
	  
	 public Collection getNoDeptEmployees()throws Exception
	{
		return this.getEmployeeHelper("select * from Employee where  department='temp'");
	 }
	 
	 public Collection getDepartmentDemployees(String deptId)throws Exception
	 {
	 	return this.getEmployeeHelper("select * from employee where department='"+deptId+"'");
	 }
	 public void deleteEmployeeFromDept(String employId,String deptId)throws Exception
	 {
	 	try
	 	{
	 		this.executeHelper("update employee set department='temp' where id='"+employId+"'");
	 	}
	 	catch(Exception e)
	 	{
	 		e.printStackTrace();
	 		throw e;
	 	}
	 }
	 public void resetEmploy(String employId,String deptId)throws Exception
	 {
	 	try
	 	{
			this.executeHelper("update employee set department='"+deptId+"' where id='"+employId+"'");
	 	}
	 	catch(Exception e)
	 	{
	 		e.printStackTrace();
	 		throw e;
	 	}
	 	
	 }
	 
	  private Collection getEmployeeHelper(String sql)throws Exception
	  {
	  	 Statement stmt=conn.createStatement();
	     ResultSet rst=stmt.executeQuery(sql);
	     Collection ret=new ArrayList();
	     while(rst.next())
	     {
	     	Employee temp=new Employee();
	     	temp.setId(rst.getString("id"));
	     	temp.setName(rst.getString("name"));
	     	temp.setAge(rst.getInt("age"));
	     	temp.setSalary(rst.getFloat("salary"));
	     	temp.setDepartment(rst.getString("department"));
	        ret.add(temp);
	     }
	     return ret;
	  }
	  
	  private void executeHelper(String sql)throws Exception
	  {
	  	 Statement stmt=conn.createStatement();
		 stmt.executeUpdate(sql);
	  }
}

⌨️ 快捷键说明

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