📄 pagination.java
字号:
//***************************************************************
//数据分页的类
//***************************************************************
package conn;
import java.sql.*;
import java.util.*;
import face.*;
public class Pagination
{
private ResultSet rs;
//每页显示的记录数
private int pageSize;
//总记录数
private int count = 0;
//总页数
private int pageCount;
//结果集的MetaData
private ResultSetMetaData rsmd = null;
//总列数
private int fieldCount = 0;
public Pagination()
{
}
public Pagination(FlashDbDao fdb) throws Exception
{
this.rs = fdb.getRs();
}
public void setPageSize(int pageSize)
{
this.pageSize = pageSize;
}
//-------------------------------------------------------------------------
//传递一个ResultSet对象
//-------------------------------------------------------------------------
public void setRs(ResultSet rs)
{
this.rs = rs;
}
//-------------------------------------------------------------------------
//获取一个ResultSetMetaData
//-------------------------------------------------------------------------
public ResultSetMetaData getRsmd()throws Exception
{
if (rsmd == null)
{
this.rsmd = rs.getMetaData();
}
return rsmd;
}
//-------------------------------------------------------------------------
//返回ResultSet的总列数
//-------------------------------------------------------------------------
public int getFiledCount()throws Exception
{
return getRsmd().getColumnCount();
}
//-------------------------------------------------------------------------
//返回总记录数
//-------------------------------------------------------------------------
public int getCount()throws Exception
{
this.count = 0;
rs.beforeFirst();
while(rs.next())
{
this.count++;
}
return this.count;
}
//-------------------------------------------------------------------------
//返回当前页的记录数
//-------------------------------------------------------------------------
public int getNonce(int pageNo) throws Exception
{
rs.beforeFirst();
int counter = 0;
while(rs.next() && counter < (pageNo - 1) * pageSize - 1 )counter++;
counter = 0;
while (rs.next() && counter < pageSize)counter++;
return counter;
}
//-------------------------------------------------------------------------
//返回产生的页数
//-------------------------------------------------------------------------
public int getPageCount()throws Exception
{
return getCount()%pageSize ==0 ? getCount()/pageSize : getCount()/pageSize + 1;
}
//-------------------------------------------------------------------------
//得到指定页的记录集
//-------------------------------------------------------------------------
public List getPageResult(int pageNo,ResultBean rb)throws Exception
{
rs.beforeFirst();
int counter = 0;
while(rs.next() && counter < (pageNo - 1) * pageSize - 1 )counter++;
List rl = new ArrayList();
ResultSetMetaData rsmd = rs.getMetaData();
counter = 0;
rs.previous();
while(rs.next() && counter < pageSize)
{
String temp = "";
for(int i = 0; i< rb.getAmount(); i++)
{
temp += String.valueOf(rs.getObject(i + 1)) + "#";
}
ResultBean newRb = rb.getResultBean();
newRb.setProperty(temp);
rl.add(newRb);
counter++;
}
return rl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -