我的分页显示,如果在查询语句中加入了where的条件查询,只能显示一条信息,如果不加入,却能显示多条.请问下,怎么才能解决.
<%
try{
int dipage=1;//当前页码数默认为1
String pages=request.getParameter("dipage");
if(pages==null)
{
pages="1";
}
try
{
dipage=Integer.parseInt(pages);
}
catch(Exception e)
{
dipage=1;
}
%>
<%
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql_select="select * from article where Id='"+session.getAttribute("id")+"'";
ResultSet rs=stmt.executeQuery(sql_select);
int countRecord=0;//记录条数
int countPageRecord=0;//每页记录条数
int countPage=0;//总页数
countPageRecord=10;//每页10条记录,要设置每页记录条数就更改这个变量的值
//得到记录的条数
rs.last();
countRecord=rs.getRow();
//得到总页数
if(countRecord/countPageRecord==0)
countPage=countRecord/countPageRecord;
else
countPage=countRecord/countPageRecord+1;
//把记录指针移至当前页第一条记录之前
if((dipage-1)*countPageRecord==0)
rs.beforeFirst();
else
rs.absolute((dipage-1)*countPageRecord);
%> <% int i=0; while(rs.next()){%>
<table width="965" border="1">
<tr>
<td width="434"><%=rs.getString("title")%> </td>
<td width="206"><%=rs.getString("pretime")%> </td>
<td width="161">修改</td>
<td width="136">删除</td>
</tr>
</table><% i++;
if(i>=countPageRecord) break;}%></td>
<td></td>
</tr>
<tr><%out.print("<TR><td colspan=8 align=center>");
out.print("共"+countRecord+"条记录,共"+countPage+"页,当前第"+dipage+"页,每页"+countPageRecord+"条记录,");
if(dipage==1)//当前是首页
;
else//当前不是首页
{
out.print("<a href=article.jsp?dipage=1>首页</a>,");
out.print("<a href=article.jsp?dipage="+(dipage-1)+">上一页</a>,");
}
if(dipage==countPage)//当前是末页
;
else//当前不是末页
{
out.print("<a href=article.jsp?dipage="+(dipage+1)+">下一页</a>,");
out.print("<a href=article.jsp?dipage="+countPage+">末页</a>");
}
out.print("</td></tr>");
}catch(SQLException e){out.print("查询已经结束");}
%>