Home > Database > Mysql Tutorial > 一个分页的类及调用的例子_MySQL

一个分页的类及调用的例子_MySQL

WBOY
Release: 2016-06-01 14:10:55
Original
1035 people have browsed it

  
//PageCt.java 分页的类
/*
***  @version        ***********
***  Created on 2001年6月25日, 下午14:41
**************************************
*/
package vod;
import java.sql.*;
import java.util.*;



public class PageCt
{
    private long l_start;   //开始纪录
    private long l_end;     //结束纪录
    private long l_curpage; //当前页数
    private long l_totalnum;//总记录数
    private int int_num=5;  //每页10条
    private long l_totalpage; //总的页数



    public void Init(long currentpage,long totalnum)
    {
        l_curpage = currentpage;
        l_totalnum = totalnum;



        if (currentpage>=0)
        {
             if (currentpage>=(long)Math.ceil((double)l_totalnum/(double)int_num))
                l_curpage = (long)Math.floor((double)l_totalnum/(double)int_num);
             else
                l_curpage = currentpage;
        }
        else
        {
                l_curpage = 0;
        }
        l_start = l_curpage * int_num;
        l_end   = l_start + int_num;
        if (l_end > l_totalnum)
                l_end = l_totalnum;
        l_totalpage = (long)Math.ceil((double)l_totalnum/(double)int_num);
    }
    public long getCurpage()
    {
        return l_curpage;
    }
    public long getPrepage()
    {
        if (l_curpage-1>=0)
        {
            return l_curpage-1;
        }
        else
        {
            return 0;
        }
    }
    public long getNextpage()
    {
        if (l_curpage+1        {
            return l_curpage+1;
        }
        else
        {
            return l_totalpage;
        }
    }
    public long getTotalnum()
    {
        return l_totalnum;
    }
    public long getTotalpage()
    {
        return l_totalpage;
    }
    public long getStart()
    {
        return l_start;
    }
    public long getEnd()
    {
        return l_end;
    }



};
===============================================
//调用例子
/*
***  @author  马毅   ***********
***  @version        ***********
***  Created on 2001年6月12日, 下午17:13
**************************************
*/







测试




Test for Test






ResultSet rs0 = sqlbean.executeQuery("select count(*) from UserList );
rs0.next();
long data_num=rs0.getLong(1);
long Current_Page = 0;
String currentpage=(String)request.getParameter("currentpage");
if (currentpage != null && !currentpage.equals(""))
{
  Current_Page = Integer.parseInt(request.getParameter("currentpage"));
}
String Query_Page=(String)request.getParameter("Query_Page");
if (Query_Page!=null && !Query_Page.equals(""))
{
  Current_Page = Integer.parseInt(request.getParameter("Query_Page"))-1;
}
PageCt.Init(Current_Page,data_num);
long l_start = PageCt.getStart();
long l_end = PageCt.getEnd();
//查询记录
ResultSet rs = sqlbean.executeQuery("select * from UserList " );
long i=0;
while((i{
      i++;
}  
//输出查询结果
long j=0;
while(rs.next() && (i{
        j=i+1;
    String col2 = rs.getString(2);
    String col3 = rs.getString(3);
    String col4 = rs.getString(4);
    String col5 = rs.getString(5);
    String col6 = rs.getString(6);
    String col7 = rs.getString(7);
    String col8 = rs.getString(8);
    //打印所显示的数据
    out.println("");
    out.println("");
    out.println("");
    out.println("");
    if (col8!=null && !col8.equals(""))
    {
        out.println("");
    }
    out.println("
" + j + "、"+(col2==null?"":col2)+"
答案:"+(col3==null?"":col3)+"
  选项1:"+(col4==null?"":col4)+"   选项2:"+(col5==null?"":col5)+"
  选项3:"+(col6==null?"":col6)+"   选项4:"+(col7==null?"":col7)+"
备注:"+col8+"

");
    i++;
}
%>









共  条 / 页 查看第  页 >上页 >下页















问题包含 > 答案包含 > 选项包含 >




添加


 
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template