注册 登录
编程论坛 J2EE论坛

分页显示中出现的问题

寂寞天涯人 发布于 2007-05-11 09:24, 639 次点击

我的分页显示,如果在查询语句中加入了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")%>&nbsp;</td>
<td width="206"><%=rs.getString("pretime")%>&nbsp;</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("查询已经结束");}

%>

4 回复
#2
支离破碎2007-05-11 09:39
你加where id=xxx当然只会有一条记录了。你加这个条件干什么?
#3
寂寞天涯人2007-05-11 11:07

把那张表上的I相同的ID的记录都显示出来

#4
支离破碎2007-05-11 11:14
where id like "I%"
#5
黄袖标2007-05-11 13:12
这个不是什么问题哦...where出来是什么就是什么...你where id&gt;1 就有n条了...不过where要写你自己的逻辑条件哦
1