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

📄 pageableresultset.java

📁 oa办公管理系统。一些小型的企业办公管理用的系统。一个月废寝忘食的结果。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.soft.pagecut;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.Ref;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;


public class PageableResultSet 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+" SQL=");//+this.getCommand());
    }
}
public int getInt(String columnName) throws SQLException {
    try {
        return rs.getInt(columnName);
    }
    catch (SQLException e) {//这里是为了增加一些出错信息的内容便于调试
        throw new SQLException (e.toString()+" columnName="
            +columnName+" SQL=");//+this.getCommand());
    }
}
//……  
//  只有在Pageable接口中新增的方法才需要自己的写方法处理。
/**方法注释可参考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 (java.sql.SQLException e) {
    }
}
public void pageFirst() throws java.sql.SQLException {
    int row=(curPage-1)*pageSize+1;
    rs.absolute(row);
}
public void pageLast() throws java.sql.SQLException {
    int row=(curPage-1)*pageSize+getPageRowsCount();
    rs.absolute(row);
}
public void setPageSize(int pageSize) {
    if(pageSize>=0){
   this.pageSize=pageSize;
        curPage=1;
    }
}  
//PageableResultSet2的构造方法:
public PageableResultSet(java.sql.ResultSet rs) throws java.sql.SQLException {
    if(rs==null) throw new SQLException("given ResultSet is NULL","user");

    rs.last();
    rowsCount=rs.getRow();
    rs.beforeFirst();
    this.rs=rs;
}  

/*如果要提高效率,可以利用select count(*) 语句取得所有记录数,注释掉构造函数的rs.last();rowsCount=rs.getRow();rs.beforeFirst();三句。在调用构造函数后调用此方法获得所有的记录,参数是select count(*)后的结果集
*/
public void setRowsCount(java.sql.ResultSet rs)throws java.sql.SQLException {
   if(rs==null) throw new SQLException("given ResultSet is NULL","user");
   rowsCount=rs.getInt(1);
}
public boolean absolute(int row) throws SQLException {
	// TODO Auto-generated method stub
	return false;
}
public void afterLast() throws SQLException {
	// TODO Auto-generated method stub
	
}
public void beforeFirst() throws SQLException {
	// TODO Auto-generated method stub
	
}
public void cancelRowUpdates() throws SQLException {
	// TODO Auto-generated method stub
	
}
public void clearWarnings() throws SQLException {
	// TODO Auto-generated method stub
	
}
public void close() throws SQLException {
	// TODO Auto-generated method stub
	
}
public void deleteRow() throws SQLException {
	// TODO Auto-generated method stub
	
}
public int findColumn(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public boolean first() throws SQLException {
	// TODO Auto-generated method stub
	return false;
}
public Array getArray(int i) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Array getArray(String colName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public InputStream getAsciiStream(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public InputStream getAsciiStream(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public BigDecimal getBigDecimal(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public InputStream getBinaryStream(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public InputStream getBinaryStream(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Blob getBlob(int i) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Blob getBlob(String colName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public boolean getBoolean(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return false;
}
public boolean getBoolean(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return false;
}
public byte getByte(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public byte getByte(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public byte[] getBytes(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public byte[] getBytes(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Reader getCharacterStream(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Reader getCharacterStream(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Clob getClob(int i) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Clob getClob(String colName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public int getConcurrency() throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public String getCursorName() throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Date getDate(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return rs.getDate(columnIndex);
}
public Date getDate(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return rs.getDate(columnName);
}
public Date getDate(int columnIndex, Calendar cal) throws SQLException {
	// TODO Auto-generated method stub
	return rs.getDate(columnIndex, cal);
}
public Date getDate(String columnName, Calendar cal) throws SQLException {
	// TODO Auto-generated method stub
	return rs.getDate(columnName, cal);
}
public double getDouble(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public double getDouble(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public int getFetchDirection() throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public int getFetchSize() throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public float getFloat(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public float getFloat(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public int getInt(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return rs.getInt(columnIndex);
}

public long getLong(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public long getLong(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return 0;
}
public ResultSetMetaData getMetaData() throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Object getObject(int columnIndex) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Object getObject(String columnName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Object getObject(int i, Map<String, Class<?>> map) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Object getObject(String colName, Map<String, Class<?>> map) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Ref getRef(int i) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public Ref getRef(String colName) throws SQLException {
	// TODO Auto-generated method stub
	return null;
}
public int getRow() throws SQLException {
	// TODO Auto-generated method stub
	rs.last();

⌨️ 快捷键说明

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