jsp+javabean实现数据分页,连接的数据库是sql server2000
希望给出详细的说明,一个连接sql2000的代码(用户名:sa,密码:123456),数据库名:student,表名:studlist.分页的javabean代码以及连接...
希望给出详细的说明,一个连接sql2000的代码(用户名:sa,密码:123456),数据库名:student,表名:studlist.分页的javabean代码以及连接javabean的jsp代码。
展开
展开全部
在数据库中写语句!
create database mydb
go
use mydb
go
create table news
(id varchar(50) primary key,
name varchar(50)
)
go
insert into news values('020','sss')
insert into news values('021','扰迅ttt')
insert into news values('022','uuu')
insert into news values('001','aaa')
insert into news values('002','bbb')
insert into news values('003','ccc')
insert into news values('竖毕004','aaa')
insert into news values('005','ddd')
insert into news values('006','eee')
insert into news values('007','fff')
insert into news values('008','ggg')
insert into news values('009','hhh')
insert into news values('010','iii')
insert into news values('011','jjj')
insert into news values('012','kkk')
insert into news values('013','lll')
insert into news values('014','mmm')
insert into news values('015','nnn')
insert into news values('016','ooo')
insert into news values('017','ppp')
insert into news values('018','qqq')
insert into news values('019','rrr')
go
select * from news
go
create proc proc_cursor --定义存储过程
@pagesize int, --每页有多少条数据
@pageindex int, --第几页
@pagetotal int output --总页数
as
begin
declare @total int,@start int,@end int,@id varchar(10),@name varchar(10),@i int
--定义几个变量,作用后面解释
declare mycur scroll cursor
for
select * from news order by ID
--定义一个滚动游标
open mycur
--打开游标
set @total = @@cursor_rows
--得到总的记录数
if @total> 0
begin
if @total % @pagesize = 0
set @pagetotal = @total / @pagesize
else
set @pagetotal = @total / @pagesize + 1
--得到总页数
if @pageindex < 1 set @pageindex = 1
if @pageindex > @pagetotal
set @pageindex = @pagetotal
--检查输入页数,确保它在1到总页数之间
set @start = (@pageindex-1)*@pagesize+1
--游标第一次移动到的位置,比如我们需要第11到15条记录,那么这个参数的值是11
set @end= @pageindex*@pagesize
--游标第二次移动到的位缓纤此置,如上,这个值应该是15
if @end > @total
set @end = @total
--确保第二次移动不超过记录的总条数
set @i=@start
while(@i<=@end)
begin
fetch absolute @i from mycur into @id,@name
print @id+' '+@name
set @i=@i+1
end
end
else
begin
set @pagetotal = 0
select top 0 * from news
end
close mycur
--关闭游标
deallocate mycur
--释放游标
end
go
declare @pagetotal int
exec proc_cursor 5,7, @pagetotal output
--执行存储过程
print ' '
print '共'+convert(varchar(10),@pagetotal)+'页'
go
drop proc proc_cursor
--删除存储过程
use master
go
drop database mydb
--删除数据库
go
然后你在直接调用就OK啦么!
create database mydb
go
use mydb
go
create table news
(id varchar(50) primary key,
name varchar(50)
)
go
insert into news values('020','sss')
insert into news values('021','扰迅ttt')
insert into news values('022','uuu')
insert into news values('001','aaa')
insert into news values('002','bbb')
insert into news values('003','ccc')
insert into news values('竖毕004','aaa')
insert into news values('005','ddd')
insert into news values('006','eee')
insert into news values('007','fff')
insert into news values('008','ggg')
insert into news values('009','hhh')
insert into news values('010','iii')
insert into news values('011','jjj')
insert into news values('012','kkk')
insert into news values('013','lll')
insert into news values('014','mmm')
insert into news values('015','nnn')
insert into news values('016','ooo')
insert into news values('017','ppp')
insert into news values('018','qqq')
insert into news values('019','rrr')
go
select * from news
go
create proc proc_cursor --定义存储过程
@pagesize int, --每页有多少条数据
@pageindex int, --第几页
@pagetotal int output --总页数
as
begin
declare @total int,@start int,@end int,@id varchar(10),@name varchar(10),@i int
--定义几个变量,作用后面解释
declare mycur scroll cursor
for
select * from news order by ID
--定义一个滚动游标
open mycur
--打开游标
set @total = @@cursor_rows
--得到总的记录数
if @total> 0
begin
if @total % @pagesize = 0
set @pagetotal = @total / @pagesize
else
set @pagetotal = @total / @pagesize + 1
--得到总页数
if @pageindex < 1 set @pageindex = 1
if @pageindex > @pagetotal
set @pageindex = @pagetotal
--检查输入页数,确保它在1到总页数之间
set @start = (@pageindex-1)*@pagesize+1
--游标第一次移动到的位置,比如我们需要第11到15条记录,那么这个参数的值是11
set @end= @pageindex*@pagesize
--游标第二次移动到的位缓纤此置,如上,这个值应该是15
if @end > @total
set @end = @total
--确保第二次移动不超过记录的总条数
set @i=@start
while(@i<=@end)
begin
fetch absolute @i from mycur into @id,@name
print @id+' '+@name
set @i=@i+1
end
end
else
begin
set @pagetotal = 0
select top 0 * from news
end
close mycur
--关闭游标
deallocate mycur
--释放游标
end
go
declare @pagetotal int
exec proc_cursor 5,7, @pagetotal output
--执行存储过程
print ' '
print '共'+convert(varchar(10),@pagetotal)+'页'
go
drop proc proc_cursor
--删除存储过程
use master
go
drop database mydb
--删除数据库
go
然后你在直接调用就OK啦么!
展开全部
<%-- --%>
<c:if test="${sessionScope.currentPage eq 1}">
<tr>
<td colspan="2" align="right">
上一页|
<a href="doshowproductlist?currentPage=${sessionScope.currentPage+1}" class="nav">下一页</a>
</td>
</tr>
</c:if>
<c:if test="${sessionScope.currentPage eq sessionScope.maxPage}">
<tr>
<td colspan="2" align="right">
<a href="森清doshowproductlist?currentPage=${sessionScope.currentPage-1}" class="nav">上一页</a>|
下一页
</td>
</tr>
</c:if>
<c:if test="${sessionScope.currentPage gt 1 and sessionScope.currentPage lt sessionScope.maxPage}">
<tr>
<td colspan="2" align="right">
<a href="doshowproductlist?currentPage=${sessionScope.currentPage-1}" class="nav">上一页</a>|
<a href="此樱前doshowproductlist?currentPage=${sessionScope.currentPage+1}" class="nav">下一页</a>
</颂闷td>
</tr>
</c:if>
<%-- <tr>
<td colspan="2" align="right"><a href="showProductList.jsp?page=" class="nav">上一页</a>|
<a href="showProductList.jsp?page=" class="nav">下一页</a></td>
</tr> --%>
</table>
<c:if test="${sessionScope.currentPage eq 1}">
<tr>
<td colspan="2" align="right">
上一页|
<a href="doshowproductlist?currentPage=${sessionScope.currentPage+1}" class="nav">下一页</a>
</td>
</tr>
</c:if>
<c:if test="${sessionScope.currentPage eq sessionScope.maxPage}">
<tr>
<td colspan="2" align="right">
<a href="森清doshowproductlist?currentPage=${sessionScope.currentPage-1}" class="nav">上一页</a>|
下一页
</td>
</tr>
</c:if>
<c:if test="${sessionScope.currentPage gt 1 and sessionScope.currentPage lt sessionScope.maxPage}">
<tr>
<td colspan="2" align="right">
<a href="doshowproductlist?currentPage=${sessionScope.currentPage-1}" class="nav">上一页</a>|
<a href="此樱前doshowproductlist?currentPage=${sessionScope.currentPage+1}" class="nav">下一页</a>
</颂闷td>
</tr>
</c:if>
<%-- <tr>
<td colspan="2" align="right"><a href="showProductList.jsp?page=" class="nav">上一页</a>|
<a href="showProductList.jsp?page=" class="nav">下一页</a></td>
</tr> --%>
</table>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询