mysql怎么算分页 mysql分页显示的语句( 三 )


PageNum = 1;
}
else{
PageNum = javang.Integer.parseInt(strPageNum);将字符串转换成整型
if(PageNum1) PageNum = 1;
}
if(PageNumPageNumCount) PageNum = PageNumCount;调整待显示的页码
%
head
meta -equiv="Content-Type" content="text/; charset=gb2312"
titleJSP例程 - 数据分页显示 -JDK1.2 /title
/head
body
%
if(PageNumCount0){
out.println(PageNum);显示数据,此处只简单的显示页数
}
/*需要显示的数据,在此处显示
、、、
例如:
*/
显示一个简单的表格
%
table border=1 cellspacing="0" cellpadding="0"
tr
th总数/th
th页数/th
/tr
tr
th%=PageNumCount%/th
th%=PageNum%/th
/tr
/table
第%=PageNum%页 共%=PageNumCount%页
%if(PageNumPageNumCount){%a href="https://www.04ip.com/post/show_page.jsp?page=%=PageNum+1%"下一页/a%}%
%if(PageNum1){%a href="https://www.04ip.com/post/show_page?page=%=PageNum-1%"上一页/a%}%
/body
/
---------------------------------
一个bean,按照文档说的用 。也希望你给出修改意见 。
package mshtang;
/**
* pTitle: DataBaseQuery/p
* pDescription: 用于数据库翻页查询操作/p
* pCopyright: 厦门一方软件公司版权所有Copyright (c) 2002/p
* pCompany: 厦门一方软件公司/p
* @author 小唐蔡
* @version 1.0
*/
import java.sql.*;
import javax.servlet..*;
import java.util.*;
import mshtang.StringAction;
public class DataBaseQuery
{
private HttpServletRequest request;
private StringAction S;
private String sql;
private String userPara;
private String[][] resultArray;
private String[] columnNameArray;
private String[] columnTypeArray;
private int pageSize;
private int columnCount;
private int currentPageNum;
private int currentPageRecordNum;
private int totalPages;
private int pageStartRecord;
private int totalRecord;
private static boolean initSuccessful;
private String currentJSPPageName;
private String displayMessage;
public DataBaseQuery()
{
S = new StringAction();
sql = "";
pageSize = 10;
totalRecord = 0;
initSuccessful = false;
currentJSPPageName = "";
displayMessage = "";
columnNameArray = null;
columnTypeArray = null;
currentPageRecordNum = 0;
columnCount = 0;
}
/**功能:数据库初始化操作 , 其它操作的前提 。
*
* @param conn:数据库连接;
* @param request:jsp页面request对象;
* @param querySQL:查询语句;
* @param pageSize:每页显示记录数;
* @param startPageNum:开始显示页码
*/
public void init(Connection conn, HttpServletRequest request, String querySQL, int pageSize, int startPageNum)
{
if(conn != null)
{
this.request = request;
this.sql = request.getParameter("querySQL");
this.userPara = request.getParameter("userPara");
if(sql == null || sql.equals(""))
{
sql = querySQL;
}
if(this.userPara == null)
{
this.userPara = "";
}
if(S.isContains(sql, "select;from", ";", true))
{
try
{
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
ResultSetMetaData r *** d = rs.getMetaData();
columnCount = r *** d.getColumnCount();
columnNameArray = new String[columnCount];
columnTypeArray = new String[columnCount];
String columnName;
String value;
while(rs.next())
{
totalRecord++;

推荐阅读