1.排序很简单了 2.序号可以在输出的时候用jsp语句生成,另一个思路是生成一个带有序号的查询结果记录集,SQL语句可以实现如下: select IDENTITY(int,1,1) as Nbr,test.UserCode into #tmp from test select * from #tmp 3.分页显示的时候注意把查询条件作为一个参数传递过去;假如序号是由JSP程序生成的,则分页时该序号由页数来进行计算当前页的起始序号是多少
分页怎么实现还能说的清楚典吗? 还有怎么通过jsp得到序号,rs.getrow(); 还有吗?
我的一个详细的jsp分页程序!(oracle+jsp+apache) 一 前提 希望最新的纪录在开头给你的表建立查询: 表:mytable 查询:create or replace view as mytable_view from mytable order by id desc 其中,最好使用序列号create sequence mytable_sequence 来自动增加你的纪录id号 二 源程序 <%String sConn="你的连接" Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn=DriverManager.getConnection(sConn,"你的用户名","密码"); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); Statement stmtcount=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rs=stmt.executeQuery("select * from mytable_view"); String sqlcount="select count(*) from mytable_view"; ResultSet rscount=stmtcount.executeQuery(sqlcount); int pageSize=你的每页显示纪录数; int rowCount=0; //总的记录数 while (rscount.next()){ rowCount=rscount.getInt(1); } int pageCount; //总的页数 int currPage; //当前页数 String strPage; strPage=request.getParameter("page"); if (strPage==null){ currPage=1; } else{ currPage=Integer.parseInt(strPage); if (currPage<1) currPage=1; } pageCount=(rowCount+pageSize-1)/pageSize; if (currPage>pageCount) currPage=pageCount; int thepage=(currPage-1)*pageSize; int n=0; rs.absolute(thepage+1); while (n<(pageSize)&&!rs.isAfterLast()){%> 你要罗列的纪录 <% rs.next(); n++; } %> <%rs.close(); rscount.close(); stmt.close(); stmtcount.close(); conn.close(); %> //下面是 第几页等 <form name="sinfo" method="post" action="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>" onSubmit="return testform(this)"> 第<%=currPage%>页 共<%=pageCount%>页 共<%=rowCount%>条 <%if(currPage>1){%><a href="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>">首页</a><%}%> <%if(currPage>1){%><a href="sbinfo_index.jsp?page=<%=currPage-1%>&condition=<%=condition%>&type=<%=type%>">上一页</a><%}%> <%if(currPage<pageCount){%><a href="sbinfo_index.jsp?page=<%=currPage+1%>&condition=<%=condition%>&type=<%=type%>">下一页</a><%}%> <%if(pageCount>1){%><a href="sbinfo_index.jsp?page=<%=pageCount%>&condition=<%=condition%>&type=<%=type%>">尾页</a><%}%> 跳到<input type="text" name="page" size="4" style="font-size:9px">页 <input type="submit" name="submit" size="4" value="GO" style="font-size:9px"> </form> 希望大家喜欢
呵呵,JSP得到序号就是这样 int i=0;//这就是序号了 i=(pagenum-1)*pagecount;//显示页数乘以显示的记录数 while(rs.next()){ i++; out.println("序号"+i) }
其中viewPage的定义如下: <script language="Javascript"> <!-- function viewPage(pageID){ document.frmtopage.pagetoshow.value=pageID+"" document.frmtopage.submit() }
!--> </script> 2、在计算页数时必须得到查询语句的记录总数,使用count(*) 方法 totalSQL="select count(*) from (" + strSQL + ") as temp" 执行totalSQL 则得到总记录数。 注意:避免在strSQL中包含“order by”语句,如果有则除去,否则会出错。去掉“order by”子句对于获取总记录数没有任何影响。 3、直接返回要显示页的记录,不必返回所有记录 SQL 语句的写法如下: pageSQL="select IDENTITY(int,1,1) as Nbr,* into #tmp From (" +strSQL + ") as temp order by Nbr select * from #tmp where nbr between 41 and 50 drop table #tmp " 上述返回了第41到50条记录,根据具体页数进行修改。
其中viewPage的定义如下: <script language="Javascript"> <!-- function viewPage(pageID){ document.frmtopage.pagetoshow.value=pageID+"" document.frmtopage.submit() }
!--> </script> 2、在计算页数时必须得到查询语句的记录总数,使用count(*) 方法 totalSQL="select count(*) from (" + strSQL + ") as temp" 执行totalSQL 则得到总记录数。 注意:避免在strSQL中包含“order by”语句,如果有则除去,否则会出错。去掉“order by”子句对于获取总记录数没有任何影响。 3、直接返回要显示页的记录,不必返回所有记录 SQL 语句的写法如下: pageSQL="select IDENTITY(int,1,1) as Nbr,* into #tmp From (" +strSQL + ") as temp order by Nbr select * from #tmp where nbr between 41 and 50 drop table #tmp " 上述返回了第41到50条记录,根据具体页数进行修改。
2.序号可以在输出的时候用jsp语句生成,另一个思路是生成一个带有序号的查询结果记录集,SQL语句可以实现如下:
select IDENTITY(int,1,1) as Nbr,test.UserCode into #tmp from test
select * from #tmp
3.分页显示的时候注意把查询条件作为一个参数传递过去;假如序号是由JSP程序生成的,则分页时该序号由页数来进行计算当前页的起始序号是多少
还有怎么通过jsp得到序号,rs.getrow();
还有吗?
int i=0;//这就是序号了
i=(pagenum-1)*pagecount;//显示页数乘以显示的记录数
while(rs.next()){
i++;
out.println("序号"+i)
}
DBMS:MS SQLServer 2000 中文版
其中strSQLWhere,查询语句的Where子句
1.为了能够将查询语句也传递到下一页,所以必须将“上页”、“下页”等等放在"Form"里,同时将查询用到的SQL语句作为一个hidden进行传递如下:
<form name=frmtopage method=post action=PDMShow.jsp>
<input type=hidden name=paramSQLWhere value=“<%=strSQLWhere%>">
<a href=javascript:viewPage(1)>首页</a>
....
转到第 <input type=text size=3 name=pagetoshow class=buttontext> 页
</form>
其中viewPage的定义如下:
<script language="Javascript">
<!--
function viewPage(pageID){
document.frmtopage.pagetoshow.value=pageID+""
document.frmtopage.submit()
}
!-->
</script>
2、在计算页数时必须得到查询语句的记录总数,使用count(*) 方法
totalSQL="select count(*) from (" + strSQL + ") as temp"
执行totalSQL 则得到总记录数。
注意:避免在strSQL中包含“order by”语句,如果有则除去,否则会出错。去掉“order by”子句对于获取总记录数没有任何影响。
3、直接返回要显示页的记录,不必返回所有记录 SQL 语句的写法如下:
pageSQL="select IDENTITY(int,1,1) as Nbr,* into #tmp From (" +strSQL + ") as temp order by Nbr select * from #tmp where nbr between 41 and 50 drop table #tmp "
上述返回了第41到50条记录,根据具体页数进行修改。
DBMS:MS SQLServer 2000 中文版
其中strSQLWhere,查询语句的Where子句
1.为了能够将查询语句也传递到下一页,所以必须将“上页”、“下页”等等放在"Form"里,同时将查询用到的SQL语句作为一个hidden进行传递如下:
<form name=frmtopage method=post action=PDMShow.jsp>
<input type=hidden name=paramSQLWhere value=“<%=strSQLWhere%>">
<a href=javascript:viewPage(1)>首页</a>
....
转到第 <input type=text size=3 name=pagetoshow class=buttontext> 页
</form>
其中viewPage的定义如下:
<script language="Javascript">
<!--
function viewPage(pageID){
document.frmtopage.pagetoshow.value=pageID+""
document.frmtopage.submit()
}
!-->
</script>
2、在计算页数时必须得到查询语句的记录总数,使用count(*) 方法
totalSQL="select count(*) from (" + strSQL + ") as temp"
执行totalSQL 则得到总记录数。
注意:避免在strSQL中包含“order by”语句,如果有则除去,否则会出错。去掉“order by”子句对于获取总记录数没有任何影响。
3、直接返回要显示页的记录,不必返回所有记录 SQL 语句的写法如下:
pageSQL="select IDENTITY(int,1,1) as Nbr,* into #tmp From (" +strSQL + ") as temp order by Nbr select * from #tmp where nbr between 41 and 50 drop table #tmp "
上述返回了第41到50条记录,根据具体页数进行修改。