首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

读取数据库的留言板信息,分页显示出错解决办法

2013-09-11 
读取数据库的留言板信息,分页显示出错这个是我查看留言板的代码bodyp aligncenter所有访客留言/p

读取数据库的留言板信息,分页显示出错
这个是我查看留言板的代码

<body>
<p align="center">所有访客留言</p> 
<table width="732" height="*" border="1" align="center" cellpadding="1" cellspacing="0" bordercolordark="#ffffff" bordercolor="#ffffff" bordercolorlight="#0066ff">
  <tr bgcolor="#CCCCFF">
  <td height="22" colspan="5" align="center"><a href="index.jsp?choice=5.jsp">增加留言</a></td>
  </tr>
  <%
Connection con = DriverManager.getConnection("jdbc:odbc:banji");
Statement sql = con.createStatement();
ResultSet rs = sql.executeQuery("select * from message ORDER BY m_date DESC");
String color="";
String strpages=(String)request.getParameter("pages");
int pages=0;
if(strpages==null){
pages=0;
}else{
  pages=Integer.parseInt(strpages);
}
rs.last();
int sqan=4,i=0,fcount=0;
int count=rs.getRow();
int countpage=count/sqan;

if(count%sqan>0) countpage=countpage+1;
if(pages<0) pages=0;
if(pages>countpage-1) pages=countpage-1;
fcount=pages*sqan+1;
int fpage=(count-fcount)/sqan+1;
out.print(fpage);
rs.absolute(fcount);
rs.previous();

while(rs.next()){
  int id=rs.getInt("id");
  String username=rs.getString("m_name");
  String time=rs.getString("m_date");
  String title=rs.getString("m_title");
  String email=rs.getString("m_email");
  String content=rs.getString("m_info");
  if(content==null) content="";
  if(color==""){
  color="#ffffff";
}else{
  color="";
}
%>
  <tr bgcolor="<%=color%>">
  <td align="center" width="86" height="22"><div align="left">留言人:</div></td>
  <td align="center" width="158"><%=username%>&nbsp;</td>
  <td height="22" colspan="2" align="left">留言主题:</td>
  <td width="298" height="22" align="center"><%=title%>&nbsp;</td>
  </tr>
  <tr bgcolor="<%=color%>">
  <td width="86" height="22" align="center"><div align="left">日期:</div></td>
  <td width="158" height="22" align="center"><%=time%></td>
  <td height="22" colspan="3" rowspan="3" align="left" valign="top"><%=content%>&nbsp;</td>
  </tr>
  <tr bgcolor="<%=color%>">
  <td height="22" align="center"><div align="left">Email:</div></td>
  <td height="22" align="center"><%=email%>&nbsp;</td>
  </tr>
  <tr bgcolor="<%=color%>">

  <%
i++;if(i==sqan) break;
  }
try{
con.close();
}catch(Exception e){
}
%>
  </tr>
  <tr align="right" bgcolor="#CCCCFF">
  <td height="22" colspan="5">第<%=(pages+1)%>/<%=countpage%>页&nbsp;&nbsp;


<a href="view_ly.jsp?pages=<%=(pages-1)%>上一页</a>&nbsp;&nbsp;
<a href="view_ly.jsp?pages=<%=(pages+1)%>下一页</a></td>
  </tr>
</table>
</body>



然后运行后报错:

org.apache.jasper.JasperException: An exception occurred processing JSP page /view_ly.jsp at line 27

24: }else{
25: pages=Integer.parseInt(strpages);
26: }
27: rs.last();
28: int sqan=4,i=0,fcount=0;
29: int count=rs.getRow();
30: int countpage=count/sqan;


高手帮我看看,改下代码,谢谢了

[解决办法]
rs.last();
没有用过,分页我一般会把数据库的内容取出来放到list集合里。
有多少条 list.size()就知道
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html

热点排行