在网上看了好多的分页程序,有好多hibernate的或是jdbcTemplate的 ,反正很多啦,,,后来一想自己能不能直接用Jdbc来做啊,,,你想你用hibernate或jdbcTemplate 它们都封装的也都是jdbc...
后来参考了一篇文章...是extends ResultSet Interface
具体的处理实现类则是实现这个接口
超长,哈,好多方法没有实现...其实实现类都是用的ResultSet来处理,还是交给了jdbc来处理,我们只要把得到的东西 "代理"一下即可.
jsp页面
index.jsp
后来参考了一篇文章...是extends ResultSet Interface
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author Administrator
*
*/
public interface IPagination extends ResultSet {
/**
* 返回总页数
*/
int getTotalPages();
//返回当前页的记录条数
int getPageRowsCount();
//得到分页大小
int getPageSize();
//转到指定页
void gotoPage(int page);
//设置分页大小
void setPageSize(int pageSize);
//返回总记录行数
int getRowsCount();
//转到当前页的第一条记录
void pageFirst() throws SQLException;
//转到当前页最后一条记录
void pageLast() throws SQLException;
//返回当前页码
int getCurPage();
}
具体的处理实现类则是实现这个接口
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 PaginationeImpl implements IPagination {
/**
* default constructors
*/
public PaginationeImpl() {
}
/**transfer ResultSet as parameter constructors
* @param rs
*/
public PaginationeImpl(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;
}
/*
* (non-Javadoc)
*
* @see controller.Pageable#getCurPage()
*/
public int getCurPage() {
return curPage;
}
/**
* @return
*/
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;
}
/*
* (non-Javadoc)
*
* @see controller.Pageable#getPageRowsCount()
*/
public int getPageRowsCount() {
if (pageSize == 0)
return rowsCount;
if (getRowsCount() == 0)
return 0;
if (curPage != getPageCount())
return pageSize;
return rowsCount - (getPageCount() - 1) * pageSize;
}
/*
* (non-Javadoc)
*
* @see controller.Pageable#getPageSize()
*/
public int getPageSize() {
return pageSize;
}
/*
* (non-Javadoc)
*
* @see controller.Pageable#getRowsCount()
*/
public int getRowsCount() {
return rowsCount != 0 ? rowsCount : 0;
}
/*
* (non-Javadoc)
*
* @see controller.Pageable#getTotalPages()
*/
public int getTotalPages() {
return 0;
}
/*
* (non-Javadoc)
*
* @see controller.Pageable#gotoPage(int)
*/
public void gotoPage(int page) {
if (rs == null)
return;
if (page < 1)
page = 1;
if (page > this.getPageCount())
page = getPageCount();
int row = (page - 1) * pageSize + 1;
try {
rs.absolute(row);
curPage = page;
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.toString());
}
}
/*
* (non-Javadoc)
*
* @see controller.Pageable#pageFirst()
*/
public void pageFirst() throws SQLException {
int row = (curPage - 1) * pageSize + 1;
rs.absolute(row);
}
/*
* (non-Javadoc)
*
* @see controller.Pageable#pageLast()
*/
public void pageLast() throws SQLException {
int row = (curPage - 1) * pageSize + this.getRowsCount();
rs.absolute(row);
}
/*
* (non-Javadoc)
*
* @see controller.Pageable#setPageSize(int)
*/
public void setPageSize(int pageSize) {
if (pageSize >= 0)
this.pageSize = pageSize;
this.curPage = 1;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#absolute(int)
*/
public boolean absolute(int row) throws SQLException {
return rs.absolute(row);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#afterLast()
*/
public void afterLast() throws SQLException {
if (rs != null)
rs.afterLast();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#beforeFirst()
*/
public void beforeFirst() throws SQLException {
if (rs != null)
rs.beforeFirst();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#cancelRowUpdates()
*/
public void cancelRowUpdates() throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#clearWarnings()
*/
public void clearWarnings() throws SQLException {
rs.clearWarnings();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#close()
*/
public void close() throws SQLException {
if (rs != null)
rs.close();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#deleteRow()
*/
public void deleteRow() throws SQLException {
rs.deleteRow();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#findColumn(java.lang.String)
*/
public int findColumn(String columnName) throws SQLException {
return rs.findColumn(columnName);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#first()
*/
public boolean first() throws SQLException {
return rs.first();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getArray(int)
*/
public Array getArray(int i) throws SQLException {
return rs.getArray(i);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getArray(java.lang.String)
*/
public Array getArray(String colName) throws SQLException {
return rs.getArray(colName);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getAsciiStream(int)
*/
public InputStream getAsciiStream(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getAsciiStream(java.lang.String)
*/
public InputStream getAsciiStream(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBigDecimal(int)
*/
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBigDecimal(java.lang.String)
*/
public BigDecimal getBigDecimal(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBigDecimal(int, int)
*/
public BigDecimal getBigDecimal(int columnIndex, int scale)
throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBigDecimal(java.lang.String, int)
*/
public BigDecimal getBigDecimal(String columnName, int scale)
throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBinaryStream(int)
*/
public InputStream getBinaryStream(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBinaryStream(java.lang.String)
*/
public InputStream getBinaryStream(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBlob(int)
*/
public Blob getBlob(int i) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBlob(java.lang.String)
*/
public Blob getBlob(String colName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBoolean(int)
*/
public boolean getBoolean(int columnIndex) throws SQLException {
return rs.getBoolean(columnIndex);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBoolean(java.lang.String)
*/
public boolean getBoolean(String columnName) throws SQLException {
return rs.getBoolean(columnName);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getByte(int)
*/
public byte getByte(int columnIndex) throws SQLException {
return 0;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getByte(java.lang.String)
*/
public byte getByte(String columnName) throws SQLException {
return 0;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBytes(int)
*/
public byte[] getBytes(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getBytes(java.lang.String)
*/
public byte[] getBytes(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getCharacterStream(int)
*/
public Reader getCharacterStream(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getCharacterStream(java.lang.String)
*/
public Reader getCharacterStream(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getClob(int)
*/
public Clob getClob(int i) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getClob(java.lang.String)
*/
public Clob getClob(String colName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getConcurrency()
*/
public int getConcurrency() throws SQLException {
return 0;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getCursorName()
*/
public String getCursorName() throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getDate(int)
*/
public Date getDate(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getDate(java.lang.String)
*/
public Date getDate(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getDate(int, java.util.Calendar)
*/
public Date getDate(int columnIndex, Calendar cal) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getDate(java.lang.String, java.util.Calendar)
*/
public Date getDate(String columnName, Calendar cal) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getDouble(int)
*/
public double getDouble(int columnIndex) throws SQLException {
return 0;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getDouble(java.lang.String)
*/
public double getDouble(String columnName) throws SQLException {
return 0;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getFetchDirection()
*/
public int getFetchDirection() throws SQLException {
return 0;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getFetchSize()
*/
public int getFetchSize() throws SQLException {
return rs.getFetchSize();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getFloat(int)
*/
public float getFloat(int columnIndex) throws SQLException {
return rs.getFloat(columnIndex);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getFloat(java.lang.String)
*/
public float getFloat(String columnName) throws SQLException {
return rs.getFloat(columnName);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getInt(int)
*/
public int getInt(int columnIndex) throws SQLException {
return rs.getInt(columnIndex);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getInt(java.lang.String)
*/
public int getInt(String columnName) throws SQLException {
return rs.getInt(columnName);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getLong(int)
*/
public long getLong(int columnIndex) throws SQLException {
return rs.getLong(columnIndex);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getLong(java.lang.String)
*/
public long getLong(String columnName) throws SQLException {
return rs.getLong(columnName);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getMetaData()
*/
public ResultSetMetaData getMetaData() throws SQLException {
return rs.getMetaData();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getObject(int)
*/
public Object getObject(int columnIndex) throws SQLException {
return rs.getObject(columnIndex);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getObject(java.lang.String)
*/
public Object getObject(String columnName) throws SQLException {
return rs.getObject(columnName);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getObject(int, java.util.Map)
*/
public Object getObject(int i, Map<String, Class<?>> map)
throws SQLException {
return rs.getObject(i, map);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getObject(java.lang.String, java.util.Map)
*/
public Object getObject(String colName, Map<String, Class<?>> map)
throws SQLException {
return rs.getObject(colName, map);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getRef(int)
*/
public Ref getRef(int i) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getRef(java.lang.String)
*/
public Ref getRef(String colName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getRow()
*/
public int getRow() throws SQLException {
return rs.getRow();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getShort(int)
*/
public short getShort(int columnIndex) throws SQLException {
return rs.getShort(columnIndex);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getShort(java.lang.String)
*/
public short getShort(String columnName) throws SQLException {
return rs.getShort(columnName);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getStatement()
*/
public Statement getStatement() throws SQLException {
return rs.getStatement();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getString(int)
*/
public String getString(int columnIndex) throws SQLException {
return rs.getString(columnIndex);
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getString(java.lang.String)
*/
public String getString(String columnName) throws SQLException {
try {
return rs.getString(columnName);
} catch (SQLException e) {
e.printStackTrace();
throw new SQLException(e.toString() + " columnName " + columnName
+ " SQL ");
}
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getTime(int)
*/
public Time getTime(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getTime(java.lang.String)
*/
public Time getTime(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getTime(int, java.util.Calendar)
*/
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getTime(java.lang.String, java.util.Calendar)
*/
public Time getTime(String columnName, Calendar cal) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getTimestamp(int)
*/
public Timestamp getTimestamp(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getTimestamp(java.lang.String)
*/
public Timestamp getTimestamp(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getTimestamp(int, java.util.Calendar)
*/
public Timestamp getTimestamp(int columnIndex, Calendar cal)
throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getTimestamp(java.lang.String,
* java.util.Calendar)
*/
public Timestamp getTimestamp(String columnName, Calendar cal)
throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getType()
*/
public int getType() throws SQLException {
return 0;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getURL(int)
*/
public URL getURL(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getURL(java.lang.String)
*/
public URL getURL(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getUnicodeStream(int)
*/
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getUnicodeStream(java.lang.String)
*/
public InputStream getUnicodeStream(String columnName) throws SQLException {
return null;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#getWarnings()
*/
public SQLWarning getWarnings() throws SQLException {
return rs.getWarnings();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#insertRow()
*/
public void insertRow() throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#isAfterLast()
*/
public boolean isAfterLast() throws SQLException {
return rs.isAfterLast();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#isBeforeFirst()
*/
public boolean isBeforeFirst() throws SQLException {
return rs.isBeforeFirst();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#isFirst()
*/
public boolean isFirst() throws SQLException {
return rs.isFirst();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#isLast()
*/
public boolean isLast() throws SQLException {
return rs.isLast();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#last()
*/
public boolean last() throws SQLException {
return rs.last();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#moveToCurrentRow()
*/
public void moveToCurrentRow() throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#moveToInsertRow()
*/
public void moveToInsertRow() throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#next()
*/
public boolean next() throws SQLException {
return rs.next();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#previous()
*/
public boolean previous() throws SQLException {
return rs.previous();
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#refreshRow()
*/
public void refreshRow() throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#relative(int)
*/
public boolean relative(int rows) throws SQLException {
return false;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#rowDeleted()
*/
public boolean rowDeleted() throws SQLException {
return false;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#rowInserted()
*/
public boolean rowInserted() throws SQLException {
return false;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#rowUpdated()
*/
public boolean rowUpdated() throws SQLException {
return false;
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#setFetchDirection(int)
*/
public void setFetchDirection(int direction) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#setFetchSize(int)
*/
public void setFetchSize(int rows) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateArray(int, java.sql.Array)
*/
public void updateArray(int columnIndex, Array x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateArray(java.lang.String, java.sql.Array)
*/
public void updateArray(String columnName, Array x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateAsciiStream(int, java.io.InputStream, int)
*/
public void updateAsciiStream(int columnIndex, InputStream x, int length)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateAsciiStream(java.lang.String,
* java.io.InputStream, int)
*/
public void updateAsciiStream(String columnName, InputStream x, int length)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBigDecimal(int, java.math.BigDecimal)
*/
public void updateBigDecimal(int columnIndex, BigDecimal x)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBigDecimal(java.lang.String,
* java.math.BigDecimal)
*/
public void updateBigDecimal(String columnName, BigDecimal x)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBinaryStream(int, java.io.InputStream, int)
*/
public void updateBinaryStream(int columnIndex, InputStream x, int length)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBinaryStream(java.lang.String,
* java.io.InputStream, int)
*/
public void updateBinaryStream(String columnName, InputStream x, int length)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBlob(int, java.sql.Blob)
*/
public void updateBlob(int columnIndex, Blob x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBlob(java.lang.String, java.sql.Blob)
*/
public void updateBlob(String columnName, Blob x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBoolean(int, boolean)
*/
public void updateBoolean(int columnIndex, boolean x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBoolean(java.lang.String, boolean)
*/
public void updateBoolean(String columnName, boolean x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateByte(int, byte)
*/
public void updateByte(int columnIndex, byte x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateByte(java.lang.String, byte)
*/
public void updateByte(String columnName, byte x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBytes(int, byte[])
*/
public void updateBytes(int columnIndex, byte[] x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateBytes(java.lang.String, byte[])
*/
public void updateBytes(String columnName, byte[] x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateCharacterStream(int, java.io.Reader, int)
*/
public void updateCharacterStream(int columnIndex, Reader x, int length)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateCharacterStream(java.lang.String,
* java.io.Reader, int)
*/
public void updateCharacterStream(String columnName, Reader reader,
int length) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateClob(int, java.sql.Clob)
*/
public void updateClob(int columnIndex, Clob x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateClob(java.lang.String, java.sql.Clob)
*/
public void updateClob(String columnName, Clob x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateDate(int, java.sql.Date)
*/
public void updateDate(int columnIndex, Date x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateDate(java.lang.String, java.sql.Date)
*/
public void updateDate(String columnName, Date x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateDouble(int, double)
*/
public void updateDouble(int columnIndex, double x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateDouble(java.lang.String, double)
*/
public void updateDouble(String columnName, double x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateFloat(int, float)
*/
public void updateFloat(int columnIndex, float x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateFloat(java.lang.String, float)
*/
public void updateFloat(String columnName, float x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateInt(int, int)
*/
public void updateInt(int columnIndex, int x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateInt(java.lang.String, int)
*/
public void updateInt(String columnName, int x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateLong(int, long)
*/
public void updateLong(int columnIndex, long x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateLong(java.lang.String, long)
*/
public void updateLong(String columnName, long x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateNull(int)
*/
public void updateNull(int columnIndex) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateNull(java.lang.String)
*/
public void updateNull(String columnName) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateObject(int, java.lang.Object)
*/
public void updateObject(int columnIndex, Object x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateObject(java.lang.String, java.lang.Object)
*/
public void updateObject(String columnName, Object x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateObject(int, java.lang.Object, int)
*/
public void updateObject(int columnIndex, Object x, int scale)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateObject(java.lang.String, java.lang.Object,
* int)
*/
public void updateObject(String columnName, Object x, int scale)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateRef(int, java.sql.Ref)
*/
public void updateRef(int columnIndex, Ref x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateRef(java.lang.String, java.sql.Ref)
*/
public void updateRef(String columnName, Ref x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateRow()
*/
public void updateRow() throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateShort(int, short)
*/
public void updateShort(int columnIndex, short x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateShort(java.lang.String, short)
*/
public void updateShort(String columnName, short x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateString(int, java.lang.String)
*/
public void updateString(int columnIndex, String x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateString(java.lang.String, java.lang.String)
*/
public void updateString(String columnName, String x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateTime(int, java.sql.Time)
*/
public void updateTime(int columnIndex, Time x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateTime(java.lang.String, java.sql.Time)
*/
public void updateTime(String columnName, Time x) throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateTimestamp(int, java.sql.Timestamp)
*/
public void updateTimestamp(int columnIndex, Timestamp x)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#updateTimestamp(java.lang.String,
* java.sql.Timestamp)
*/
public void updateTimestamp(String columnName, Timestamp x)
throws SQLException {
}
/*
* (non-Javadoc)
*
* @see java.sql.ResultSet#wasNull()
*/
public boolean wasNull() throws SQLException {
return false;
}
protected ResultSet rs = null ;
protected int rowsCount = 0 ;
protected int pageSize = 0 ;
protected int curPage = 0 ;
protected String command = "" ;
}
超长,哈,好多方法没有实现...其实实现类都是用的ResultSet来处理,还是交给了jdbc来处理,我们只要把得到的东西 "代理"一下即可.
jsp页面
index.jsp
<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="jdbc page test">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String driver = "com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost/test?characterEncoding=UTF-8&useUnicode=true";
String username = "root";
String password = "root";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url,username,password);
Statement stm = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stmcount = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = null;
ResultSet rscount = null;
String selectSql = "select * from data order by id desc";
String countSql = "select count(*) from data";
rs = stm.executeQuery(selectSql);
rscount = stmcount .executeQuery(countSql);
int pageSize = 20;
int rowCount = 0;
while(rscount.next())
rowCount = rscount.getInt(1 );
int pageCount;
int curPage;
String strPage = request.getParameter("page");
curPage = strPage == null ? 1 : Integer.parseInt(strPage) ;
curPage = curPage <1 ? 1 :curPage;
pageCount = (rowCount + pageSize -1)/pageSize;
curPage = curPage > pageCount ? pageCount : curPage;
int thePage = (curPage - 1) * pageSize;
int n = 0;
rs.absolute(thePage + 1 );
%>
<table border="1" bgcolor="gray">
<tr>
<td align="center">NO.</td>
<td align="center">ID</td>
<td align="center">title</td>
<td align="center">content</td>
<td align="center">create_time</td>
</tr>
<%
while(n < pageSize && !rs.isAfterLast()){
%>
<tr> <td align="center">
<%=((curPage-1)*pageSize)+(n+1)%>
</td>
<td align="center">
<%= rs.getInt("id")%>
</td>
<td align="center">
<%=rs.getString("title")%>
</td>
<td>
<%=rs.getString("content")%>
</td>
<td>
<%=rs.getString("create_time")%>
</td></tr>
<%
rs.next();
n++;
}
%>
</table>
<p>
<center>
第<%=curPage%>页 共<%=pageCount%>页 共<%=rowCount%>条
<%if(curPage>1){%><a href="index.jsp">首页</a><%}%>
<%if(curPage>1){%><a href="index.jsp?page=<%=curPage-1%>">上一页</a><%}%>
<%if(curPage<pageCount){%><a href="index.jsp?page=<%=curPage+1%>">下一页</a><%}%>
<%if(pageCount>1){%><a href="index.jsp?page=<%=pageCount%>">尾页</a><%}%>
</center>
</body>
</html>