标签:tco url extends 水果 man result this ast 知识
在上文中我们已经从数据库中获取到了数据,并且可以显示在html页面上。本文是继上文之后,将获取到的数据集进行处理之后显示在页面上。
从所接触的知识面,这里想到了有两种方案。
一、使用容器将获得的数据保存起来,然后显示到页面上。
二、重写ResultSet类方法,实现ResultSet的分页,并使用jsp显示到页面上。
两种方式都可行,考虑到大数据的效率问题,这里选择了方法二。
一、重写ResultSet类,实现记录集的分页
1.添加Pageable接口
package com.cn.page; import java.sql.ResultSet; public interface Pageable extends ResultSet { int getPageCount(); int getPageRowsCount(); int getPageSize(); void gotoPage(int page); void setPageSize(int pageSize); int getRowsCount(); void pageFirst() throws java.sql.SQLException; void pageLast() throws java.sql.SQLException; int getCurrentPage(); }
2.添加PageableResultSet实现类
package com.cn.page; 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.NClob; import java.sql.Ref; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.RowId; import java.sql.SQLException; import java.sql.SQLWarning; import java.sql.SQLXML; 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 ResultSet rs=null; protected int rowsCount; protected int pageSize; protected int currentPage; protected String command = ""; public PageableResultSet(java.sql.ResultSet rs) throws java.sql.SQLException{ if(null == rs){ throw new SQLException("given REsultSet is NULL","user"); } rs.last(); rowsCount = rs.getRow(); System.out.println(rowsCount); rs.beforeFirst(); this.rs = rs; } @Override //获取总页数 public int getPageCount() { // TODO Auto-generated method stub if(0 == rowsCount){ return 0; } if(0 == pageSize){ return 1; } double tmpD = (double)rowsCount/pageSize; int tmpl=(int)tmpD; if(tmpD > tmpl){ tmpl++; } return tmpl; } @Override //获取当前页的记录条数 public int getPageRowsCount() { // TODO Auto-generated method stub if(0 == pageSize){ return rowsCount; } if(0 == getRowsCount()){ return 0; } if(currentPage != getPageCount()){ return pageSize; } return rowsCount - (getPageCount() - 1)*pageSize; } @Override public int getPageSize() { return pageSize; } //跳转到第几页 public void gotoPage(int page) { // TODO Auto-generated method stub if(null == rs){ return; } if(page < 1){ page = 1; } if(page > getPageCount()) { page = getPageCount(); } int row = (page -1)*pageSize + 1; try { rs.absolute(row); currentPage = page; }catch (java.sql.SQLException e){ e.printStackTrace(); } } @Override public void setPageSize(int pageSize) { // TODO Auto-generated method stub if(pageSize >= 0){ this.pageSize = pageSize; currentPage = 1; } } @Override //总的记录条数 public int getRowsCount() { // TODO Auto-generated method stub return rowsCount; } @Override public void pageFirst() throws SQLException { // TODO Auto-generated method stub int row = (currentPage - 1)*pageSize + 1; rs.absolute(row); } @Override public void pageLast() throws SQLException { // TODO Auto-generated method stub int row = (currentPage - 1)*pageSize + getPageRowsCount(); rs.absolute(row); } @Override public int getCurrentPage() { // TODO Auto-generated method stub return currentPage; } @Override public boolean next() throws SQLException { // TODO Auto-generated method stub return rs.next(); } @Override public void close() throws SQLException { // TODO Auto-generated method stub rs.close(); } @Override public boolean wasNull() throws SQLException { // TODO Auto-generated method stub return rs.wasNull(); } @Override public String getString(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getString(columnIndex); } @Override public boolean getBoolean(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getBoolean(columnIndex); } @Override public byte getByte(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getByte(columnIndex); } @Override public short getShort(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getByte(columnIndex); } @Override public int getInt(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getInt(columnIndex); } @Override public long getLong(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getLong(columnIndex); } @Override public float getFloat(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getFloat(columnIndex); } @Override public double getDouble(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getDouble(columnIndex); } @SuppressWarnings("deprecation") @Override public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { // TODO Auto-generated method stub return rs.getBigDecimal(columnIndex, scale); } @Override public byte[] getBytes(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getBytes(columnIndex); } @Override public Date getDate(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getDate(columnIndex); } @Override public Time getTime(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getTime(columnIndex); } @Override public Timestamp getTimestamp(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getTimestamp(columnIndex); } @Override public InputStream getAsciiStream(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getAsciiStream(columnIndex); } @SuppressWarnings("deprecation") @Override public InputStream getUnicodeStream(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getUnicodeStream(columnIndex); } @Override public InputStream getBinaryStream(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getBinaryStream(columnIndex); } @Override public String getString(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getString(columnLabel); } @Override public boolean getBoolean(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getBoolean(columnLabel); } @Override public byte getByte(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getByte(columnLabel); } @Override public short getShort(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getShort(columnLabel); } @Override public int getInt(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getInt(columnLabel); } @Override public long getLong(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getLong(columnLabel); } @Override public float getFloat(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getFloat(columnLabel); } @Override public double getDouble(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getDouble(columnLabel); } @SuppressWarnings("deprecation") @Override public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { // TODO Auto-generated method stub return rs.getBigDecimal(columnLabel, scale); } @Override public byte[] getBytes(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getBytes(columnLabel); } @Override public Date getDate(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getDate(columnLabel); } @Override public Time getTime(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getTime(columnLabel); } @Override public Timestamp getTimestamp(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getTimestamp(columnLabel); } @Override public InputStream getAsciiStream(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getAsciiStream(columnLabel); } @SuppressWarnings("deprecation") @Override public InputStream getUnicodeStream(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getUnicodeStream(columnLabel); } @Override public InputStream getBinaryStream(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getBinaryStream(columnLabel); } @Override public SQLWarning getWarnings() throws SQLException { // TODO Auto-generated method stub return rs.getWarnings(); } @Override public void clearWarnings() throws SQLException { // TODO Auto-generated method stub rs.clearWarnings(); } @Override public String getCursorName() throws SQLException { // TODO Auto-generated method stub return rs.getCursorName(); } @Override public ResultSetMetaData getMetaData() throws SQLException { // TODO Auto-generated method stub return rs.getMetaData(); } @Override public Object getObject(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getObject(columnIndex); } @Override public Object getObject(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getObject(columnLabel); } @Override public int findColumn(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.findColumn(columnLabel); } @Override public Reader getCharacterStream(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getCharacterStream(columnIndex); } @Override public Reader getCharacterStream(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getCharacterStream(columnLabel); } @Override public BigDecimal getBigDecimal(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getBigDecimal(columnIndex); } @Override public BigDecimal getBigDecimal(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getBigDecimal(columnLabel); } @Override public boolean isBeforeFirst() throws SQLException { // TODO Auto-generated method stub return rs.isBeforeFirst(); } @Override public boolean isAfterLast() throws SQLException { // TODO Auto-generated method stub return rs.isAfterLast(); } @Override public boolean isFirst() throws SQLException { // TODO Auto-generated method stub return rs.isFirst(); } @Override public boolean isLast() throws SQLException { // TODO Auto-generated method stub return rs.isLast(); } @Override public void beforeFirst() throws SQLException { // TODO Auto-generated method stub rs.beforeFirst(); } @Override public void afterLast() throws SQLException { // TODO Auto-generated method stub rs.afterLast(); } @Override public boolean first() throws SQLException { // TODO Auto-generated method stub return rs.first(); } @Override public boolean last() throws SQLException { // TODO Auto-generated method stub return rs.last(); } @Override public int getRow() throws SQLException { // TODO Auto-generated method stub return rs.getRow(); } @Override public boolean absolute(int row) throws SQLException { // TODO Auto-generated method stub return rs.absolute(row); } @Override public boolean relative(int rows) throws SQLException { // TODO Auto-generated method stub return rs.relative(rows); } @Override public boolean previous() throws SQLException { // TODO Auto-generated method stub return rs.previous(); } @Override public void setFetchDirection(int direction) throws SQLException { // TODO Auto-generated method stub rs.setFetchDirection(direction); } @Override public int getFetchDirection() throws SQLException { // TODO Auto-generated method stub return rs.getFetchDirection(); } @Override public void setFetchSize(int rows) throws SQLException { // TODO Auto-generated method stub rs.setFetchSize(rows); } @Override public int getFetchSize() throws SQLException { // TODO Auto-generated method stub return rs.getFetchSize(); } @Override public int getType() throws SQLException { // TODO Auto-generated method stub return rs.getType(); } @Override public int getConcurrency() throws SQLException { // TODO Auto-generated method stub return rs.getConcurrency(); } @Override public boolean rowUpdated() throws SQLException { // TODO Auto-generated method stub return rs.rowUpdated(); } @Override public boolean rowInserted() throws SQLException { // TODO Auto-generated method stub return rs.rowInserted(); } @Override public boolean rowDeleted() throws SQLException { // TODO Auto-generated method stub return rs.rowDeleted(); } @Override public void updateNull(int columnIndex) throws SQLException { // TODO Auto-generated method stub rs.updateNull(columnIndex); } @Override public void updateBoolean(int columnIndex, boolean x) throws SQLException { // TODO Auto-generated method stub rs.updateBoolean(columnIndex, x); } @Override public void updateByte(int columnIndex, byte x) throws SQLException { // TODO Auto-generated method stub rs.updateByte(columnIndex, x); } @Override public void updateShort(int columnIndex, short x) throws SQLException { // TODO Auto-generated method stub rs.updateShort(columnIndex, x); } @Override public void updateInt(int columnIndex, int x) throws SQLException { // TODO Auto-generated method stub rs.updateInt(columnIndex, x); } @Override public void updateLong(int columnIndex, long x) throws SQLException { // TODO Auto-generated method stub rs.updateLong(columnIndex, x); } @Override public void updateFloat(int columnIndex, float x) throws SQLException { // TODO Auto-generated method stub rs.updateFloat(columnIndex, x); } @Override public void updateDouble(int columnIndex, double x) throws SQLException { // TODO Auto-generated method stub rs.updateDouble(columnIndex, x); } @Override public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { // TODO Auto-generated method stub rs.updateBigDecimal(columnIndex, x); } @Override public void updateString(int columnIndex, String x) throws SQLException { // TODO Auto-generated method stub rs.updateString(columnIndex, x); } @Override public void updateBytes(int columnIndex, byte[] x) throws SQLException { // TODO Auto-generated method stub rs.updateBytes(columnIndex, x); } @Override public void updateDate(int columnIndex, Date x) throws SQLException { // TODO Auto-generated method stub rs.updateDate(columnIndex, x); } @Override public void updateTime(int columnIndex, Time x) throws SQLException { // TODO Auto-generated method stub rs.updateTime(columnIndex, x); } @Override public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { // TODO Auto-generated method stub rs.updateTimestamp(columnIndex, x); } @Override public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { // TODO Auto-generated method stub rs.updateAsciiStream(columnIndex, x, length); } @Override public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { // TODO Auto-generated method stub rs.updateBinaryStream(columnIndex, x, length); } @Override public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { // TODO Auto-generated method stub rs.updateCharacterStream(columnIndex, x, length); } @Override public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { // TODO Auto-generated method stub rs.updateObject(columnIndex, x, scaleOrLength); } @Override public void updateObject(int columnIndex, Object x) throws SQLException { // TODO Auto-generated method stub rs.updateObject(columnIndex, x); } @Override public void updateNull(String columnLabel) throws SQLException { // TODO Auto-generated method stub rs.updateNull(columnLabel); } @Override public void updateBoolean(String columnLabel, boolean x) throws SQLException { // TODO Auto-generated method stub rs.updateBoolean(columnLabel, x); } @Override public void updateByte(String columnLabel, byte x) throws SQLException { // TODO Auto-generated method stub rs.updateByte(columnLabel, x); } @Override public void updateShort(String columnLabel, short x) throws SQLException { // TODO Auto-generated method stub rs.updateShort(columnLabel, x); } @Override public void updateInt(String columnLabel, int x) throws SQLException { // TODO Auto-generated method stub rs.updateInt(columnLabel, x); } @Override public void updateLong(String columnLabel, long x) throws SQLException { // TODO Auto-generated method stub rs.updateLong(columnLabel, x); } @Override public void updateFloat(String columnLabel, float x) throws SQLException { // TODO Auto-generated method stub rs.updateFloat(columnLabel, x); } @Override public void updateDouble(String columnLabel, double x) throws SQLException { // TODO Auto-generated method stub rs.updateDouble(columnLabel, x); } @Override public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { // TODO Auto-generated method stub rs.updateBigDecimal(columnLabel, x); } @Override public void updateString(String columnLabel, String x) throws SQLException { // TODO Auto-generated method stub rs.updateString(columnLabel, x); } @Override public void updateBytes(String columnLabel, byte[] x) throws SQLException { // TODO Auto-generated method stub rs.updateBytes(columnLabel, x); } @Override public void updateDate(String columnLabel, Date x) throws SQLException { // TODO Auto-generated method stub rs.updateDate(columnLabel, x); } @Override public void updateTime(String columnLabel, Time x) throws SQLException { // TODO Auto-generated method stub rs.updateTime(columnLabel, x); } @Override public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { // TODO Auto-generated method stub rs.updateTimestamp(columnLabel, x); } @Override public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { // TODO Auto-generated method stub rs.updateAsciiStream(columnLabel, x, length); } @Override public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { // TODO Auto-generated method stub rs.updateBinaryStream(columnLabel, x, length); } @Override public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { // TODO Auto-generated method stub rs.updateCharacterStream(columnLabel, reader, length); } @Override public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { // TODO Auto-generated method stub rs.updateObject(columnLabel, x, scaleOrLength); } @Override public void updateObject(String columnLabel, Object x) throws SQLException { // TODO Auto-generated method stub rs.updateObject(columnLabel, x); } @Override public void insertRow() throws SQLException { // TODO Auto-generated method stub rs.insertRow(); } @Override public void updateRow() throws SQLException { // TODO Auto-generated method stub rs.updateRow(); } @Override public void deleteRow() throws SQLException { // TODO Auto-generated method stub rs.deleteRow(); } @Override public void refreshRow() throws SQLException { // TODO Auto-generated method stub rs.refreshRow(); } @Override public void cancelRowUpdates() throws SQLException { // TODO Auto-generated method stub rs.cancelRowUpdates(); } @Override public void moveToInsertRow() throws SQLException { // TODO Auto-generated method stub rs.moveToInsertRow(); } @Override public void moveToCurrentRow() throws SQLException { // TODO Auto-generated method stub rs.moveToCurrentRow(); } @Override public Statement getStatement() throws SQLException { // TODO Auto-generated method stub return rs.getStatement(); } @Override public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException { // TODO Auto-generated method stub return rs.getObject(columnIndex, map); } @Override public Ref getRef(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getRef(columnIndex); } @Override public Blob getBlob(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getBlob(columnIndex); } @Override public Clob getClob(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getClob(columnIndex); } @Override public Array getArray(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getArray(columnIndex); } @Override public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException { // TODO Auto-generated method stub return rs.getObject(columnLabel, map); } @Override public Ref getRef(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getRef(columnLabel); } @Override public Blob getBlob(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getBlob(columnLabel); } @Override public Clob getClob(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getClob(columnLabel); } @Override public Array getArray(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getArray(columnLabel); } @Override public Date getDate(int columnIndex, Calendar cal) throws SQLException { // TODO Auto-generated method stub return rs.getDate(columnIndex, cal); } @Override public Date getDate(String columnLabel, Calendar cal) throws SQLException { // TODO Auto-generated method stub return rs.getDate(columnLabel, cal); } @Override public Time getTime(int columnIndex, Calendar cal) throws SQLException { // TODO Auto-generated method stub return rs.getTime(columnIndex, cal); } @Override public Time getTime(String columnLabel, Calendar cal) throws SQLException { // TODO Auto-generated method stub return rs.getTime(columnLabel, cal); } @Override public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { // TODO Auto-generated method stub return rs.getTimestamp(columnIndex, cal); } @Override public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { // TODO Auto-generated method stub return rs.getTimestamp(columnLabel, cal); } @Override public URL getURL(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getURL(columnIndex); } @Override public URL getURL(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getURL(columnLabel); } @Override public void updateRef(int columnIndex, Ref x) throws SQLException { // TODO Auto-generated method stub rs.updateRef(columnIndex, x); } @Override public void updateRef(String columnLabel, Ref x) throws SQLException { // TODO Auto-generated method stub rs.updateRef(columnLabel, x); } @Override public void updateBlob(int columnIndex, Blob x) throws SQLException { // TODO Auto-generated method stub rs.updateBlob(columnIndex, x); } @Override public void updateBlob(String columnLabel, Blob x) throws SQLException { // TODO Auto-generated method stub rs.updateBlob(columnLabel, x); } @Override public void updateClob(int columnIndex, Clob x) throws SQLException { // TODO Auto-generated method stub rs.updateClob(columnIndex, x); } @Override public void updateClob(String columnLabel, Clob x) throws SQLException { // TODO Auto-generated method stub rs.updateClob(columnLabel, x); } @Override public void updateArray(int columnIndex, Array x) throws SQLException { // TODO Auto-generated method stub rs.updateArray(columnIndex, x); } @Override public void updateArray(String columnLabel, Array x) throws SQLException { // TODO Auto-generated method stub rs.updateArray(columnLabel, x); } @Override public RowId getRowId(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getRowId(columnIndex); } @Override public RowId getRowId(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getRowId(columnLabel); } @Override public void updateRowId(int columnIndex, RowId x) throws SQLException { // TODO Auto-generated method stub rs.updateRowId(columnIndex, x); } @Override public void updateRowId(String columnLabel, RowId x) throws SQLException { // TODO Auto-generated method stub rs.updateRowId(columnLabel, x); } @Override public int getHoldability() throws SQLException { // TODO Auto-generated method stub return rs.getHoldability(); } @Override public boolean isClosed() throws SQLException { // TODO Auto-generated method stub return rs.isClosed(); } @Override public void updateNString(int columnIndex, String nString) throws SQLException { // TODO Auto-generated method stub rs.updateNString(columnIndex, nString); } @Override public void updateNString(String columnLabel, String nString) throws SQLException { // TODO Auto-generated method stub rs.updateNString(columnLabel, nString); } @Override public void updateNClob(int columnIndex, NClob nClob) throws SQLException { // TODO Auto-generated method stub rs.updateNClob(columnIndex, nClob); } @Override public void updateNClob(String columnLabel, NClob nClob) throws SQLException { // TODO Auto-generated method stub rs.updateNClob(columnLabel, nClob); } @Override public NClob getNClob(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getNClob(columnIndex); } @Override public NClob getNClob(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getNClob(columnLabel); } @Override public SQLXML getSQLXML(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getSQLXML(columnIndex); } @Override public SQLXML getSQLXML(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getSQLXML(columnLabel); } @Override public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { // TODO Auto-generated method stub rs.updateSQLXML(columnIndex, xmlObject); } @Override public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { // TODO Auto-generated method stub rs.updateSQLXML(columnLabel, xmlObject); } @Override public String getNString(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getNString(columnIndex); } @Override public String getNString(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getNString(columnLabel); } @Override public Reader getNCharacterStream(int columnIndex) throws SQLException { // TODO Auto-generated method stub return rs.getNCharacterStream(columnIndex); } @Override public Reader getNCharacterStream(String columnLabel) throws SQLException { // TODO Auto-generated method stub return rs.getNCharacterStream(columnLabel); } @Override public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { // TODO Auto-generated method stub rs.updateNCharacterStream(columnIndex, x, length); } @Override public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { // TODO Auto-generated method stub rs.updateNCharacterStream(columnLabel, reader, length); } @Override public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { // TODO Auto-generated method stub rs.updateAsciiStream(columnIndex, x, length); } @Override public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { // TODO Auto-generated method stub rs.updateBinaryStream(columnIndex, x, length); } @Override public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { // TODO Auto-generated method stub rs.updateCharacterStream(columnIndex, x, length); } @Override public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { // TODO Auto-generated method stub rs.updateAsciiStream(columnLabel, x, length); } @Override public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { // TODO Auto-generated method stub rs.updateBinaryStream(columnLabel, x, length); } @Override public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { // TODO Auto-generated method stub rs.updateCharacterStream(columnLabel, reader, length); } @Override public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { // TODO Auto-generated method stub rs.updateBlob(columnIndex, inputStream, length); } @Override public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { // TODO Auto-generated method stub rs.updateBlob(columnLabel, inputStream, length); } @Override public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { // TODO Auto-generated method stub rs.updateClob(columnIndex, reader, length); } @Override public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { // TODO Auto-generated method stub rs.updateClob(columnLabel, reader, length); } @Override public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { // TODO Auto-generated method stub rs.updateNClob(columnIndex, reader, length); } @Override public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { // TODO Auto-generated method stub rs.updateNClob(columnLabel, reader, length); } @Override public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { // TODO Auto-generated method stub rs.updateNCharacterStream(columnIndex, x); } @Override public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { // TODO Auto-generated method stub rs.updateNCharacterStream(columnLabel, reader); } @Override public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { // TODO Auto-generated method stub rs.updateAsciiStream(columnIndex, x); } @Override public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { // TODO Auto-generated method stub rs.updateBinaryStream(columnIndex, x); } @Override public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { // TODO Auto-generated method stub rs.updateCharacterStream(columnIndex, x); } @Override public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { // TODO Auto-generated method stub rs.updateAsciiStream(columnLabel, x); } @Override public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { // TODO Auto-generated method stub rs.updateBinaryStream(columnLabel, x); } @Override public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { // TODO Auto-generated method stub rs.updateCharacterStream(columnLabel, reader); } @Override public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { // TODO Auto-generated method stub rs.updateBlob(columnIndex, inputStream); } @Override public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { // TODO Auto-generated method stub rs.updateBlob(columnLabel, inputStream); } @Override public void updateClob(int columnIndex, Reader reader) throws SQLException { // TODO Auto-generated method stub rs.updateClob(columnIndex, reader); } @Override public void updateClob(String columnLabel, Reader reader) throws SQLException { // TODO Auto-generated method stub rs.updateClob(columnLabel, reader); } @Override public void updateNClob(int columnIndex, Reader reader) throws SQLException { // TODO Auto-generated method stub rs.updateNClob(columnIndex, reader); } @Override public void updateNClob(String columnLabel, Reader reader) throws SQLException { // TODO Auto-generated method stub rs.updateNClob(columnLabel, reader); } @Override public <T> T getObject(int columnIndex, Class<T> type) throws SQLException { // TODO Auto-generated method stub return rs.getObject(columnIndex, type); } @Override public <T> T getObject(String columnLabel, Class<T> type) throws SQLException { // TODO Auto-generated method stub return rs.getObject(columnLabel, type); } @Override public <T> T unwrap(Class<T> iface) throws SQLException { // TODO Auto-generated method stub return rs.unwrap(iface); } @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { // TODO Auto-generated method stub return rs.isWrapperFor(iface); } }
二、数据的获取及显示
<%@ page contentType="text/html" pageEncoding="GB2312" language="java"%> <%@ page import="java.sql.*"%> <%@page import="com.cn.page.Pageable"%> <%@page import="com.cn.page.PageableResultSet"%> <html> <head> <title>hello</title> </head> <body> <table border="1" spacing="2"> <%! public static final String DRIVER = "com.mysql.jdbc.Driver"; public static final String USER = "root"; public static final String PASS = "123456"; public static final String URL = "jdbc:mysql://localhost:3306/test_db"; public static final int PAGESIZE = 5; int pageCount; int curPage = 1; %> <% //一页放5个 String user = null; String pass = null; Pageable rs = null; try{ Class.forName(DRIVER); Connection con = DriverManager.getConnection(URL,USER,PASS); String sql = "SELECT * FROM fruits"; PreparedStatement pstmt = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs = new PageableResultSet(pstmt.executeQuery()); rs.setPageSize(5); String tmp = request.getParameter("curPage"); if(tmp==null){ tmp="1"; } curPage = Integer.parseInt(tmp); // out.println(curPage); rs.gotoPage(curPage); int count = 0; pageCount = rs.getPageCount(); for(int i=0;i < rs.getPageRowsCount();i++){ if(count>=PAGESIZE)break; String empno = rs.getString(1); int ename = rs.getInt(2); String job = rs.getString(3); float hiredate = rs.getFloat(4); rs.next(); count++; %> <tr> <td><%=empno%></td> <td><%=ename%></td> <td><%=job%></td> <td><%=hiredate%></td> </tr> <% } con.close(); } catch(Exception e){ } %> </table> <a href = "fruits.jsp?curPage=1" >首页</a> <a href = "fruits.jsp?curPage=<%=curPage-1%>" >上一页</a> <a href = "fruits.jsp?curPage=<%=curPage+1%>" >下一页</a> <a href = "fruits.jsp?curPage=<%=pageCount%>" >尾页</a> 第<%=curPage%>页/共<%=pageCount%>页 </body> </html>
三、html显示页面的修改
<form name="f2" id="f2" action="fruits.jsp" method="post"> <table border="0"> <tr> <td>所有水果:</td> <td colspan="2"><input type="submit" value="查看所有水果"></td> </tr> </table> </form>
至此,实现了数据的分页显示,以上代码验证通过。
标签:tco url extends 水果 man result this ast 知识
原文地址:http://www.cnblogs.com/wanzaiyimeng/p/7025885.html