分页错误

fashchina 2004-09-02 02:47:54
<%@ 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>
帮助我看看那有错误!
谢谢!
我找了半天找不到
...全文
108 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
fashchina 2004-09-02
An error occurred between lines: 5 and 67 in the jsp file: /sql_page.jsp

Generated servlet error:
D:\tomcat 4.0\work\Standalone\localhost\_\sql_0005fpage$jsp.java:79: '}' expected.
int Page=3;
^


An error occurred between lines: 5 and 67 in the jsp file: /sql_page.jsp

Generated servlet error:
D:\tomcat 4.0\work\Standalone\localhost\_\sql_0005fpage$jsp.java:82: Statement expected.
public String ShowOnePage(ResultSet rs,int Page,int PageSize)
^


An error occurred between lines: 5 and 67 in the jsp file: /sql_page.jsp

Generated servlet error:
D:\tomcat 4.0\work\Standalone\localhost\_\sql_0005fpage$jsp.java:118: Identifier expected.
sql="select * from score_manage";
^


An error occurred between lines: 75 and 112 in the jsp file: /sql_page.jsp

Generated servlet error:
D:\tomcat 4.0\work\Standalone\localhost\_\sql_0005fpage$jsp.java:135: Type expected.
if(totalrecord % PageSize==0)//如果整除
这是什么错误呀?
回复
fashchina 2004-09-02
数据库连接是没问题的了!
回复
Ronanljy 2004-09-02
有人看才怪,而且我认为楼主最好自己先尽量调试,比如说前面的数据库连接部分就可以自行调试,不用贴出来。
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-02 02:47
社区公告
暂无公告