这是JAVA分页类
package Pagination;
import java.sql.*;
import java.util.*;
public class splitPage {
private Connection con=null;
private Statement stmt=null;
private ResultSet rs=null;
private String sqlStr;
private int rowCount;
private int pageCount;
private int pageSize;
public void setCon(Connection con){
this.con=con;
if(this.con==null){
System.out.println("Failure to get a connection!");
}
else{
System.out.println("Success to get a connection!");
}
}
public void initialize(String sqlStr,int pageSize){
this.sqlStr=sqlStr;
this.pageSize=pageSize;
try{
stmt=this.con.createStatement();
rs=stmt.executeQuery(this.sqlStr);
if(rs!=null){
rs.last();
this.rowCount=rs.getRow();
rs.first();
this.pageCount=(this.rowCount-1)/this.pageSize+1;
}
}
catch(SQLException e){
System.out.println(e.toString());
}
}
public Vector getPage(int ipage){
Vector vData = new Vector();
int n=ipage;
int m=0;
m=(n-1)*this.pageSize+1;
try{
if(rs!=null){
if(n!=1){
rs.absolute(m);
}
for(int i=0;i<this.pageSize;i++){
String[] sData = new String[9];
for(int j=0;j<9;j++){
sData[j]=rs.getString(j+1);
}
if(sData==null){
break;
}
vData.addElement(sData);
rs.next();
}
}
rs.close();
stmt.close();
}
catch(SQLException e){
System.out.println(e.toString());
}
return vData;
}
public int getPageCount(){
return this.pageCount;
}
public int getRowCount(){
return this.rowCount;
}
}
下面是在JSP页面中调用-------->但调用失败
<%@ page language="java"
import="java.io.*"
import="java.sql.*"
import="java.util.*"
import="Jdbc.Dconn"
import="Pagination.splitPage"
pageEncoding="gb2312"%>
<%!
//每页显示的记录数
int pageSize=11;
String sqlStr="";
//总页数
int pageCount=0;
//总记录数
int rowCount=0;
//当前页
int showPage=1;
Connection dbcon;
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:/MyWorkspace/saleManMS/data/smmdb.mdb";
%>
<jsp:useBean id="pages" scope="session" class="Pagination.splitPage"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbcon=DriverManager.getConnection(url);
out.print("conn is ok!");
}
catch(SQLException ex){
System.out.print(ex.toString());
}
catch(ClassNotFoundException ex){
System.out.print(ex.toString());
}
pages.setCon(dbcon);
sqlStr="select * from tbcustom ORDER BY cu_id";
pages.initialize(sqlStr,pageSize);
String strPage=null;
strPage= request.getParameter("showPage");
out.print("init is ok!");
if(strPage==null){
strPage="1";
}
else{
try{
showPage=Integer.parseInt(strPage);
}
catch(NumberFormatException ex){
showPage=1;
}
if(showPage<=1){
showPage=1;
}
if(showPage>pages.getPageCount()){
showPage=pages.getPageCount();
}
}
Vector vData=pages.getPage(showPage);
out.print("vector is ok!");
%>
<html>
<head>
<base href="<%=basePath%>">
<title></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="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css" media="all">
input { background-color: rgb(0, 128, 192); }
</style>
</head>
<body>
<div align="center">
<form name="formcufm" method="post" action="">
<table width="600" border="1" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="50"></td>
<td></td>
<td align="center"><input type="button" name="cuinfoadd"
value="增加客户" on οnclick=""></td>
<td></td>
<td align="center"><input type="button" name="cuinfodel"
value="删除客户"></td>
<td></td>
<td></td>
</tr>
<tr>
<td width="50"> </td>
<td align="center">客户编号</td>
<td align="center">公司名称</td>
<td align="center" width="150">公司地址</td>
<td align="center">注册项目</td>
<td align="center">员工人数</td>
<td align="center">详细资料</td>
</tr>
<% out.print(String.valueOf(pages.getRowCount()));
for(int i=0;i<vData.size();i++){
String[] sData=(String[])vData.get(i);
%>
<tr>
<td align="center"><input type="checkbox" name="<%=sData[0]%>" value="checkbox"></td>
<td align="right"> <%=sData[0]%></td>
<td align="right"> <%=sData[0]%></td>
<td align="right"> <%=sData[0]%></td>
<td align="right"> <%=sData[0]%></td>
<td align="right"> <%=sData[0]%></td>
<td> <input type="button" name="cuinfomod0" value="详情/修改"></td>
</tr>
<%
} %>
</table>
</form>
<form action="custom_info.jsp" method="post" target="_self">
共<font color=red><%=pages.getRowCount() %></font>条
<%=pageSize %>条/页
第<font color=red><%=showPage %></font>页/共<font
color=red><%=pages.getRowCount()%></font>页
<a href="custom_info.jsp?showPage=1" target="_self">[首页]</a>
<%if(showPage>1){%>
<a href="custom_info.jsp?showPage=<%=showPage-1%>"
target="_self">[上一页]</a>
<% }
else{
%>
[上一页]
<% }
if(showPage<pages.getRowCount()){
%>
<a href="custom_info.jsp?showPage=<%=showPage+1%>"
target="_self">[下一页]</a>
<% }
else{
%>
[上一页]
<% }%>
<a href="custom_info.jsp?showPage=<%=pages.getRowCount()%>"
target="_self">[尾页]</a>
转到
<select name="showPage">
<%
for(int x=1;x<pages.getRowCount();x++){
%>
<option value="<%=x %>" <%if(showPage==x)
out.println("selected"); %>><%=x %></option>
<%} %>
</select>
页
<input type="submit" name="go" value="提交"></input>
</form>
</div>
<%
dbcon.close(); %>
</body>
</html>
请高手快快帮忙,先谢谢拉!