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

📄 resultsetpage.java

📁 采用j2ee架构做的bbs
💻 JAVA
字号:
/*
 * 创建日期 2006-4-29
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package net.icefish.page;

import java.sql.*;
/**
 * @author LittleChild
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public abstract class ResultSetPage implements Pageable {
    protected java.sql.ResultSet rs=null;
    protected int rowsCount;
    protected int pageSize;
    protected int curPage;
  //  protected String command = "";
    
//  ……
    public boolean next() throws SQLException {
        return rs.next();
    }
//    ……
    public String getString(String columnName) throws SQLException {
        try {
            return rs.getString(columnName);
        }
        catch (SQLException e) {
            throw new SQLException (e.toString()+" columnName="
                +columnName);
        }
    }

    /**方法注释可参考Pageable.java
    */
    public int getCurPage() {
        return curPage;
    }
    public int getPageCount() {
        if(rowsCount==0) return 0;
        if(pageSize==0) return 1;
        //calculate PageCount
        double tmpD=(double)rowsCount/pageSize;
        int tmpI=(int)tmpD;
        if(tmpD>tmpI) tmpI++;
        return tmpI;
    }
    public int getPageRowsCount() {
        if(pageSize==0) return rowsCount;
        if(getRowsCount()==0) return 0;
        if(curPage!=getPageCount()) return pageSize;
        return rowsCount-(getPageCount()-1)*pageSize;
    }
    public int getPageSize() {
        return pageSize;
    }
    public int getRowsCount() {
        return rowsCount;
    }
    public void gotoPage(int page) {
        if (rs == null)
            return;
        if (page < 1)
            page = 1;
        if (page > getPageCount())
            page = getPageCount();
        int row = (page - 1) * pageSize + 1;
        try {
            rs.absolute(row);
            curPage = page;
        }
        catch (SQLException e) {
        }
    }
    public void pageFirst() throws SQLException {
        int row=(curPage-1)*pageSize+1;
        rs.absolute(row);
    }
    public void pageLast() throws SQLException {
        int row=(curPage-1)*pageSize+getPageRowsCount();
        rs.absolute(row);
    }
    public void setPageSize(int pageSize) {
        if(pageSize>=0){
            this.pageSize=pageSize;
            curPage=1;
        }
    }  

    public ResultSetPage(ResultSet rs) throws SQLException {
        if(rs==null) throw new SQLException("given ResultSet is NULL","user");
        
        rs.last();
        rowsCount=rs.getRow();
        rs.beforeFirst();
        
        this.rs=rs;
    }  

    
}  

⌨️ 快捷键说明

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