📄 pagination.java
字号:
package mybean;
import java.sql.*;
public class Pagination{
private int rowsCount; //记录总数
private int pageCount; //页面总数
private int pageSize; //页面尺寸,页面记录大小
private int currentPage; //当前页数
private ResultSet rs=null;
public Pagination(ResultSet rs) throws SQLException{
try{
if(rs==null){
rowsCount=0;
}else{
rs.last();
rowsCount=rs.getRow(); //取得记录数
rs.beforeFirst();
}
}catch(SQLException ex){
ex.printStackTrace();
}
this.rs=rs;
}
public int getPageCount(){
if(rowsCount==0) return 0;
if(pageSize==0) return 0;
double tempPageCount1=(double)rowsCount/pageSize;
int tempPageCount2=(int)tempPageCount1;
if(tempPageCount2<tempPageCount1) tempPageCount2++;
return tempPageCount2;
}
//获得页面记录数
public int getPageRowsCount(){
if(pageSize==0) return rowsCount;
if(getRowsCount()==0) return 0;
if(currentPage!=getPageCount()) return pageSize;
return rowsCount-(getPageCount()-1)*pageSize;
}
//获得总记录数
public int getRowsCount(){
return rowsCount;
}
//设置分页尺寸
public void setPageSize(int pageSize){
if(pageSize>0){
this.pageSize=pageSize;
currentPage=1;
}
}
public int getCurPage(){
return currentPage;
}
//获得页面尺寸
public int getPageSize(){
return pageSize;
}
//跳转页面
public void gotoPage(int pageNumber){
if(rs==null) return;
if(pageNumber>getPageCount())
pageNumber=getPageCount();
int row=(pageNumber-1)*pageSize+1;
try{
rs.absolute(row);
currentPage=pageNumber;
}catch(java.sql.SQLException e){
}
}
public boolean next() throws SQLException{
return rs.next();
}
public Object getObject(int col) throws SQLException{
return rs.getObject(col);
}
public String getString(int colsNum) throws SQLException{
if(rs.getString(colsNum)==null)
return "";
else return rs.getString(colsNum);
}
public String getString(String colsName) throws SQLException{
if(rs.getString(colsName)==null)
return "";
else return rs.getString(colsName);
}
public int getInt(int colsNum) throws SQLException{
return rs.getInt(colsNum);
}
public int getInt(String colsName) throws SQLException{
return rs.getInt(colsName);
}
public float getFloat(int colsNum) throws SQLException{
return rs.getFloat(colsNum);
}
public float getFloat(String colsName) throws SQLException{
return rs.getFloat(colsName);
}
public String RSclose(){
try{
rs.close();
}catch(SQLException ex){
return(ex.getMessage());
}
return "ok";
}
//首页
public void gotoFirstPage(){
}
//末页
public void gotoLastPage(){
}
//上一页
public void previousPage(){
}
//下一页
public void nextPage(){
}
public void close(){
try{
if(rs!=null){
rs.close();
rs=null;
}
}catch(SQLException ex){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -