日期:2014-05-16 浏览次数:20452 次
此工程的模式是javaBean+servlet+jsp
?
1.po层
package com.inspur.po;
import java.sql.Date;
public class EmpDept {
?private int empno;
??? private String ename;
??? private String mgr;
??? private String job;
??? private Date hiredate;
??? private int sal;
??? private int comm;
??? private String dname;
??? private String loc;
??? private int deptno;
?public int getComm() {
??return comm;
?}
?public void setComm(int comm) {
??this.comm = comm;
?}
?public int getDeptno() {
??return deptno;
?}
?public void setDeptno(int deptno) {
??this.deptno = deptno;
?}
?public String getDname() {
??return dname;
?}
?public void setDname(String dname) {
??this.dname = dname;
?}
?public int getEmpno() {
??return empno;
?}
?public void setEmpno(int empno) {
??this.empno = empno;
?}
?public String getEname() {
??return ename;
?}
?public void setEname(String ename) {
??this.ename = ename;
?}
?public Date getHiredate() {
??return hiredate;
?}
?public void setHiredate(Date hiredate) {
??this.hiredate = hiredate;
?}
?public String getJob() {
??return job;
?}
?public void setJob(String job) {
??this.job = job;
?}
?public String getLoc() {
??return loc;
?}
?public void setLoc(String loc) {
??this.loc = loc;
?}
?public String getMgr() {
??return mgr;
?}
?public void setMgr(String mgr) {
??this.mgr = mgr;
?}
?public int getSal() {
??return sal;
?}
?public void setSal(int sal) {
??this.sal = sal;
?}
?public EmpDept(int empno, String ename, String mgr, String job, Date hiredate, int sal, int comm, String dname, String loc, int deptno) {
??super();
??this.empno = empno;
??this.ename = ename;
??this.mgr = mgr;
??this.job = job;
??this.hiredate = hiredate;
??this.sal = sal;
??this.comm = comm;
??this.dname = dname;
??this.loc = loc;
??this.deptno = deptno;
?}
?public EmpDept() {
??super();
?}
???
}
?
2.dao层
?
package com.inspur.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.inspur.po.EmpDept;
import com.inspur.tool.DBConn;
public class SelectEmp {
?? public List Select(int deptno, String name){
??? Connection conn=DBConn.getConn();
??? PreparedStatement pst=null;
??? ResultSet rst=null;
??? EmpDept emp=null;
??? List list=new ArrayList();
??? String sql="select s1.empno,s1.ename,s2.ename,s1.job,s1.hiredate,s1.sal,s1.comm,dname,loc,s1.deptno " +
??? ??"from emp s1,emp s2,dept " +
??? ??" where dept.deptno=s1.deptno and s2.empno=s1.mgr " +
??? ??" and s1.deptno=? and s1.ename like ?";//联表查询,s1和s2是自查询
??? try {
??pst=conn.prepareStatement(sql);
??pst.setInt(1,deptno);
??pst.setString(2,"%"+name+"%");//模糊查询
??rst=pst.executeQuery();
??while(rst.next()){
???emp=new EmpDept(rst.getInt("empno"),rst.getString(2),rst.getString(3),rst.getString("job"),rst.getDate("hiredate"),rst.getInt("sal"),rst.getInt("comm"),rst.getString("dname"),rst.getString("loc"),rst.getInt("deptno"));
???list.add(emp);
??}
??
?} catch (SQLException e) {
??// TODO Auto-generated catch block
??e.printStackTrace();
?}
? return list;?
?? }
}
?
?
3.servlet层
?
package com.inspur.servlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.inspur.dao.S