分页错误
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://CHGSNET:1433;DatabaseName=shool";
//pubs为你的数据库的
String user="sa";
String password="sa";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//String sql="select * from score_manage";
//ResultSet rs=stmt.executeQuery(sql);
//out.print("数据库操作成功,恭喜你");
String sql="";
//String key="";
//String type="";
int PageSize=6;
int Page=3;
//int TotalPage=1;
//定义函数
public String ShowOnePage(ResultSet rs,int Page,int PageSize)
{
String str="";
//先将记录指针定位到相应的位置
//try{
rs.absolute((Page-1)*PageSize+1);
//}
//catch(SQLException e)
//{
//}
for(int iPage=1;iPage<=PageSize;iPage++)
{
str+=RsToGbook(rs);
//try{
if(!rs.next()) break;
//}
//catch(Exception e){}
}
return str;
}
//显示单行记录
public String RsToGbook(ResultSet rs)
{
String tt="";
//开始
//try{
tt+="<tr>";
tt+="<td> "+ rs.getInt(1)+"</td>";
tt+="<td> "+ rs.getString("userid")+"</td>";
tt+="<td> "+ rs.getInt(1)+"</td>";
tt+="</tr>";
//}//接受
//catch(SQLException e)
//{}
return tt;
}
sql="select * from score_manage";
//try{
rs=conn.executeQuery(sql);
//}
///catch(Exception e)
///{out.print("数据库访问出错");
//}
%>
<hr size="1">
<table width="80%" border="1" align="center">
<tr>
<td>ID</td>
<td>身份证</td>
<td>成绩</td>
</tr>
<%
rsTmp=conn.executeQuery("select count(*) as mycount from score_manage");
rsTmp.next();
int totalrecord=rsTmp.getInt("mycount");
if(totalrecord % PageSize==0)//如果整除
{
totalPage=totalrecord/PageSize;
}
else//还剩下一页
{
totalPage=(int)Math.floor(totalrecord/PageSize)+1;
}
if(totalrecord==0)
{
totalPage=1;
}
rsTmp.close();
// try{
if(request.getParameter("Page")==null||request.getParameter("Page").equals(""))
{
Page=1;
}
else
{
Page=Integer.parseInt(request.getParameter("Page"));
}
// catch(java.lang.NumberFormatException e)//获得异常
// {
// Page=1;
// }
if(Page<0)
{ Page=1;
}
if(Page>totalPage)
{ Page=totalPage;
}
out.println(ShowOnePage(rs,Page,PageSize));
%>
</table>
<form name="form1" method="get" action="sql_page.jsp">
<p>
<%
if(Page!=1)
{
out.print("<a href=sql_page.jsp?page=1>第一页</a>");
out.print("<a href=sql_page.jsp?page="+(Page-1)+">上一页</a>");
}
if(Page!=totalPage)
{
out.print("<a href=sql_page.jsp?page="+(Page+1)+">下一页</a>");
out.print("<a href=sql_page.jsp?page="+total+">第一页</a>");
}
rs.close();
%>
</p>
<p>输入页数:
<input name="page" type="text" id="page">
页数:<font color="#FF0000"><%=Page%>/<%=totalPage%></font></p>
</form>
</body>
</html>
帮助我看看那有错误!
谢谢!
我找了半天找不到