zoukankan      html  css  js  c++  java
  • oracle 界面分页

    /**
     * 
     */
    package org.pan.util;
    
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.pan.contents.Contents;
    import org.pan.db.DBConnectionManager;
    import org.pan.io.ResUserIO;
    /**
     * @author admin
     *
     */
    public class PagerTools
    {
    	/**
    	 * 
    	 * @param currentPageNumber
    	 * @return
    	 * @throws Exception 
    	 */
    	public static List<ResUserIO> getResultSetByPageNumber(Integer currentPageNumber) throws Exception
    	{
    		DBConnectionManager dbMan = new DBConnectionManager();
    		ResultSet fenyeData =null;
    		Statement stmt = null;
    		Integer totleDataNumber = null;
    		List<ResUserIO> resInfoList = null;
    		try
    		{
    			stmt = dbMan.getStatement();
    			
    			totleDataNumber = getAllDataNumber(stmt);
    			String pageNumbers = ConfigTools.getInstance().getConfigByConfigName("PAGENUMBERS");
    			Integer pageNumber = Integer.valueOf(pageNumbers);
    			
    			if(Contents.NO_DATA_IN_DATEBASE.equals(totleDataNumber))
    			{
    				return null;
    			}
    			
    			boolean isFullPage = totleDataNumber>=currentPageNumber*pageNumber ? true:false;
    			
    			if(isFullPage)
    			{
    					Integer upLimit = (currentPageNumber-1)*pageNumber+1;
    					Integer downLimit = currentPageNumber*pageNumber;
    					String querySql = new StringBuffer().append("select username,phonumber,address from(select rownum r ,t1.username,t1.phonumber,address from tc_re_user t1 where rownum <=  ").append(downLimit).append(")t2 where t2.r>=").append(upLimit).toString();
    					fenyeData = stmt.executeQuery(querySql);
    			}
    			else
    			{
    				Integer upLimit = (currentPageNumber-1)*pageNumber;
    				String querySql = new StringBuffer().append("select username,phonumber,address from(select rownum r ,t1.username,t1.phonumber,address from tc_re_user t1 where rownum <=  ").append(totleDataNumber).append(")t2 where t2.r>").append(upLimit).toString();
    				fenyeData = stmt.executeQuery(querySql);
    			}
    			
    		if(null != fenyeData)
    		{
    			resInfoList = new ArrayList<ResUserIO>();
    			ResUserIO resInfo = null;
    			while(fenyeData.next())
    			{
    				resInfo = new ResUserIO();
    				resInfo.setUserName(fenyeData.getString("username"));
    				resInfo.setPhoNumber(fenyeData.getString("phonumber"));
    				resInfo.setAddress(fenyeData.getString("address"));
    				resInfoList.add(resInfo);
    			}
    		}
    		}
    		catch (SQLException e)
    		{
    			e.printStackTrace();
    		}
    		finally
    		{
    			try
    			{
    				stmt.close();
    			}
    			catch (SQLException e)
    			{
    				e.printStackTrace();
    			}
    		}
    		return resInfoList;
    	}
    	
    	public static Integer getTotlePage(Integer dateNumbers ,Integer eachPageNumber)
    	{
    		return dateNumbers%eachPageNumber==0 ? dateNumbers/eachPageNumber : dateNumbers/eachPageNumber+1;
    	}
    
    	public static Integer getAllDataNumber(Statement stmt) throws SQLException
    	{
    		ResultSet resultSet = stmt.executeQuery("select count(*) from tc_re_user");
    		Integer totleDataNumber = 0;
    		if(null != resultSet)
    		{
    			while(resultSet.next())
    			{
    				totleDataNumber = resultSet.getInt(1);
    			}
    		}
    		return totleDataNumber;
    	}	
    }
    


  • 相关阅读:
    Android升级ADT22后会报ClassNotFoundException的原因分析
    修改Android解锁界面
    Android中dip, dp, px,pt, sp之间的区别:
    移动开发:Android官方提供的支持不同屏幕大小的全部方法
    常用正则表达式
    Android多语言与国际化
    Android中的资源与国际化
    Android开发:使用Fragment改造TabActivity
    Android开发–Intent-filter属性详解
    Fragment、Activity比较——Android碎片介绍
  • 原文地址:https://www.cnblogs.com/aukle/p/3230935.html
Copyright © 2011-2022 走看看