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

📄 pageableresultset.java

📁 网络硬盘
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/**
 * 
 */
package com.zte.webfile.dal;

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.ResultSet;
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;

/**
 * @author Administrator
 * 
 */
public class PageableResultSet implements Pageable {

	protected int rowsCount;

	protected int pageSize;

	protected int currentPage;

	protected String command = "";

	protected ResultSet rs = null;

	/**
	 * @param rs
	 * @throws SQLException 
	 */
	public PageableResultSet(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;
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.nc21.exam.dal.Pageable#getCurrentPage()
	 */
	public int getCurrentPage() {
		return currentPage;
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.nc21.exam.dal.Pageable#getPageCount()
	 */
	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;

	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.nc21.exam.dal.Pageable#getPageRowsCount()
	 */
	public int getPageRowsCount() {

		if (pageSize == 0)
			return rowsCount;

		if (getRowsCount() == 0)
			return 0;

		if (currentPage != getPageCount())
			return pageSize;

		return rowsCount - (getPageCount() - 1) * pageSize;

	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.nc21.exam.dal.Pageable#getPageSize()
	 */
	public int getPageSize() {
		return pageSize;
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.nc21.exam.dal.Pageable#getRowsCount()
	 */
	public int getRowsCount() {
		return rowsCount;
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.nc21.exam.dal.Pageable#gotoPage(int)
	 */
	public void gotoPage(int page) throws SQLException {
		if (rs == null) {
			return;
		}

		if (page < 1) {
			page = 1;
		}

		if (page > getPageCount()) {
			page = getPageCount();
		}

		int row = (page - 1) * pageSize + 1;
		rs.absolute(row);
		currentPage = page;

	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.nc21.exam.dal.Pageable#pageFirst()
	 */
	public void pageFirst() throws SQLException {
		int row = (currentPage - 1) * pageSize + 1;
		rs.absolute(row);
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.nc21.exam.dal.Pageable#pageLast()
	 */
	public void pageLast() throws SQLException {
		int row = (currentPage - 1) * pageSize + getPageRowsCount();
		rs.absolute(row);
	}

	/*
	 * (非 Javadoc)
	 * 
	 * @see com.nc21.exam.dal.Pageable#setPageSize(int)
	 */
	public void setPageSize(int pageSize) {
		if (pageSize >= 0) {
			this.pageSize = pageSize;
			currentPage = 1;
		}
	}

	/**
	 * @param row
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#absolute(int)
	 */
	public boolean absolute(int row) throws SQLException {
		return rs.absolute(row);
	}

	/**
	 * @throws SQLException
	 * @see java.sql.ResultSet#afterLast()
	 */
	public void afterLast() throws SQLException {
		rs.afterLast();
	}

	/**
	 * @throws SQLException
	 * @see java.sql.ResultSet#beforeFirst()
	 */
	public void beforeFirst() throws SQLException {
		rs.beforeFirst();
	}

	/**
	 * @throws SQLException
	 * @see java.sql.ResultSet#cancelRowUpdates()
	 */
	public void cancelRowUpdates() throws SQLException {
		rs.cancelRowUpdates();
	}

	/**
	 * @throws SQLException
	 * @see java.sql.ResultSet#clearWarnings()
	 */
	public void clearWarnings() throws SQLException {
		rs.clearWarnings();
	}

	/**
	 * @throws SQLException
	 * @see java.sql.ResultSet#close()
	 */
	public void close() throws SQLException {
		rs.close();
	}

	/**
	 * @throws SQLException
	 * @see java.sql.ResultSet#deleteRow()
	 */
	public void deleteRow() throws SQLException {
		rs.deleteRow();
	}

	/**
	 * @param columnName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#findColumn(java.lang.String)
	 */
	public int findColumn(String columnName) throws SQLException {
		return rs.findColumn(columnName);
	}

	/**
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#first()
	 */
	public boolean first() throws SQLException {
		return rs.first();
	}

	/**
	 * @param i
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getArray(int)
	 */
	public Array getArray(int i) throws SQLException {
		return rs.getArray(i);
	}

	/**
	 * @param colName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getArray(java.lang.String)
	 */
	public Array getArray(String colName) throws SQLException {
		return rs.getArray(colName);
	}

	/**
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getAsciiStream(int)
	 */
	public InputStream getAsciiStream(int columnIndex) throws SQLException {
		return rs.getAsciiStream(columnIndex);
	}

	/**
	 * @param columnName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getAsciiStream(java.lang.String)
	 */
	public InputStream getAsciiStream(String columnName) throws SQLException {
		return rs.getAsciiStream(columnName);
	}

	/**
	 * @param columnIndex
	 * @param scale
	 * @return
	 * @throws SQLException
	 * @deprecated
	 * @see java.sql.ResultSet#getBigDecimal(int, int)
	 */
	public BigDecimal getBigDecimal(int columnIndex, int scale)
			throws SQLException {
		return rs.getBigDecimal(columnIndex, scale);
	}

	/**
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBigDecimal(int)
	 */
	public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
		return rs.getBigDecimal(columnIndex);
	}

	/**
	 * @param columnName
	 * @param scale
	 * @return
	 * @throws SQLException
	 * @deprecated
	 * @see java.sql.ResultSet#getBigDecimal(java.lang.String, int)
	 */
	public BigDecimal getBigDecimal(String columnName, int scale)
			throws SQLException {
		return rs.getBigDecimal(columnName, scale);
	}

	/**
	 * @param columnName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBigDecimal(java.lang.String)
	 */
	public BigDecimal getBigDecimal(String columnName) throws SQLException {
		return rs.getBigDecimal(columnName);
	}

	/**
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBinaryStream(int)
	 */
	public InputStream getBinaryStream(int columnIndex) throws SQLException {
		return rs.getBinaryStream(columnIndex);
	}

	/**
	 * @param columnName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBinaryStream(java.lang.String)
	 */
	public InputStream getBinaryStream(String columnName) throws SQLException {
		return rs.getBinaryStream(columnName);
	}

	/**
	 * @param i
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBlob(int)
	 */
	public Blob getBlob(int i) throws SQLException {
		return rs.getBlob(i);
	}

	/**
	 * @param colName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBlob(java.lang.String)
	 */
	public Blob getBlob(String colName) throws SQLException {
		return rs.getBlob(colName);
	}

	/**
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBoolean(int)
	 */
	public boolean getBoolean(int columnIndex) throws SQLException {
		return rs.getBoolean(columnIndex);
	}

	/**
	 * @param columnName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBoolean(java.lang.String)
	 */
	public boolean getBoolean(String columnName) throws SQLException {
		return rs.getBoolean(columnName);
	}

	/**
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getByte(int)
	 */
	public byte getByte(int columnIndex) throws SQLException {
		return rs.getByte(columnIndex);
	}

	/**
	 * @param columnName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getByte(java.lang.String)
	 */
	public byte getByte(String columnName) throws SQLException {
		return rs.getByte(columnName);
	}

	/**
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBytes(int)
	 */
	public byte[] getBytes(int columnIndex) throws SQLException {
		return rs.getBytes(columnIndex);
	}

	/**
	 * @param columnName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getBytes(java.lang.String)
	 */
	public byte[] getBytes(String columnName) throws SQLException {
		return rs.getBytes(columnName);
	}

	/**
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getCharacterStream(int)
	 */
	public Reader getCharacterStream(int columnIndex) throws SQLException {
		return rs.getCharacterStream(columnIndex);
	}

	/**
	 * @param columnName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getCharacterStream(java.lang.String)
	 */
	public Reader getCharacterStream(String columnName) throws SQLException {
		return rs.getCharacterStream(columnName);
	}

	/**
	 * @param i
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getClob(int)
	 */
	public Clob getClob(int i) throws SQLException {
		return rs.getClob(i);
	}

	/**
	 * @param colName
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getClob(java.lang.String)
	 */
	public Clob getClob(String colName) throws SQLException {
		return rs.getClob(colName);
	}

	/**
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getConcurrency()
	 */
	public int getConcurrency() throws SQLException {
		return rs.getConcurrency();
	}

	/**
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getCursorName()
	 */
	public String getCursorName() throws SQLException {
		return rs.getCursorName();
	}

	/**
	 * @param columnIndex
	 * @param cal
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getDate(int, java.util.Calendar)
	 */
	public Date getDate(int columnIndex, Calendar cal) throws SQLException {
		return rs.getDate(columnIndex, cal);
	}

	/**
	 * @param columnIndex
	 * @return
	 * @throws SQLException
	 * @see java.sql.ResultSet#getDate(int)
	 */
	public Date getDate(int columnIndex) throws SQLException {
		return rs.getDate(columnIndex);
	}

	/**
	 * @param columnName
	 * @param cal
	 * @return
	 * @throws SQLException

⌨️ 快捷键说明

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