javaEE mvc例子详解(五)

2014-11-23 19:41:10 · 作者: · 浏览: 101
集 geeInt(1):方法,查询表里所有数据集 } }catch(Exception e){ throw e; }finally{ try{ pstmt.close(); }catch(Exception e){ throw e; } } return count; } //验证用户名是否存在 public boolean getAllEname(String ename)throws Exception{ boolean flag=false; PreparedStatement pstmt=null; try{ String sql="SELECT COUNT(ename) FROM emp1 WHERE ename= "; pstmt=this.conn.prepareStatement(sql); pstmt.setString(1, ename); ResultSet rs=pstmt.executeQuery(); if(rs.next()){ if(rs.getInt(1)>0){ flag=true; System.out.println("impl===flag=="+rs.getInt(1)); System.out.println("impl===flag=="+flag); }else{ flag=false; } } }catch(Exception e){ throw e; }finally{ try{ pstmt.close(); }catch(Exception e){ throw e; } } return flag; } }

EmpDAOProxy

package org.lzch.dao.proxy;

import java.util.List;

import org.lzch.dao.IEmpDAO;
import org.lzch.dao.impl.EmpDAOImpl;
import org.lzch.dbc.DatabaseConnection;
import org.lzch.vo.Emp;

public class EmpDAOProxy implements IEmpDAO {
	private DatabaseConnection dbc=null;
	private IEmpDAO dao=null;
	int count=0;
	public EmpDAOProxy(){
		try{
			this.dbc=new DatabaseConnection();
		}catch(Exception e){
			e.printStackTrace();
		}
		this.dao=new EmpDAOImpl(this.dbc.getConnection());
	}
	
	public boolean doCreate(Emp emp) throws Exception {
		// TODO Auto-generated method stub
		boolean flag=false;
		try{
			if(this.dao.findEmpById(emp.getEmpno())==null){
				flag=this.dao.doCreate(emp);			//调用真实主题类
			}
		}catch(Exce
ption e){ throw e; }finally{ try{ this.dbc.closeConnection(); }catch(Exception e){ throw e; } } return flag; } public boolean doDelete(int empno) throws Exception { // TODO Auto-generated method stub boolean flag=false; try{ flag=this.dao.doDelete(empno); //调用真实主题类 }catch(Exception e){ throw e; }finally{ try{ this.dbc.closeConnection(); }catch(Exception e){ throw e; } } return flag; } public boolean doUpdate(Emp emp) throws Exception { // TODO Auto-generated method stub boolean flag=false; try{ flag=this.dao.doUpdate(emp); //调用真实主题类 }catch(Exception e){ throw e; }finally{ try{ this.dbc.closeConnection(); }catch(Exception e){ throw e; } } return flag; } public List findAll(int currentPage, int lineSize, String keyword) throws Exception { // TODO Auto-generated method stub List all=null; try{ all=this.dao.findAll(currentPage, lineSize, keyword); //调用真实主题类 count=this.dao.getAllCount(keyword); //取得最大记录数 //调用真实主题类 }catch(Exception e){ throw e; }finally{ try{ this.dbc.closeConnection(); }catch(Exception e){ throw e; } } return all; } public Emp findEmpById(int empno) throws Exception { // TODO Auto-generated method stub Emp emp=null; try{ emp=this.dao.findEmpById(empno); //调用真实主题类 }catch(Exception e){ throw e; }finally{ try{ this.dbc.closeConnection(); }catch(Exception e){ throw e; } } return emp; } public int getAllCount(String keyword) throws Exception { // TODO Auto-