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

📄 pagedao.java

📁 简单的员工管理
💻 JAVA
字号:
package com.dao;

import java.util.Vector;

import com.bean.EmpBean;
import com.db.*;

import java.sql.*;

public class PageDao implements IPage {

	public int getMaxPage() {
		int maxrow=this.getMaxRow();
		if(maxrow==0)
		{
			return 1;
		}
		return maxrow%5==0?maxrow/5:maxrow/5+1;
	}

	public int getMaxRow() {
		DBConnection dbconn=DBConnection.getDBConnection();
		Connection conn=dbconn.getConn();
		String sql="select count(*) from emp";
		PreparedStatement ps=null;
		ResultSet rst=null;
		
		try {
			ps=conn.prepareStatement(sql);
			rst=ps.executeQuery();
			if(rst.next())
			{
				return rst.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				if (rst != null) {
					rst.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return 0;
	}

	public Vector getPageData(int curpage) {
		int maxpage=this.getMaxPage();
		if(curpage<1)
		{
			curpage=1;
		}
		if(curpage>maxpage)
		{
			curpage=maxpage;
		}
		int rownum=(curpage-1)*5;
		
		String sql="select top 5 * from vwemp where id not in (select top "+rownum+" id from vwemp order by id desc ) order by id desc";
		DBConnection dbconn = DBConnection.getDBConnection();
		Connection conn = dbconn.getConn();
		
		PreparedStatement ps = null;
		ResultSet rst = null;
		Vector vc = new Vector();
		EmpPopedomDao epd = new EmpPopedomDao();

		try {
			ps = conn.prepareStatement(sql);
			rst = ps.executeQuery();
			while (rst.next()) {
				EmpBean eb = new EmpBean();
				eb.setId(rst.getString(1));
				eb.setName(rst.getString(2));
				eb.setPass(rst.getString(3));
				eb.setSex(rst.getString(4));
				eb.setAge(rst.getString(5));
				eb.setDepid(rst.getString(6));
				eb.setSchool(rst.getString(7));
				eb.setResume(rst.getString(8));
				eb.setPicture(rst.getString(9));
				eb.setDepname(rst.getString(10));
				// 查此员工的权限
				Vector vcp = epd.findByEid(eb.getId());
				if (vcp != null) {
					eb.setPopedoms(vcp);
				}
				vc.add(eb);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (rst != null) {
					rst.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return vc;
	}

}

⌨️ 快捷键说明

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