谈谈Java调用SQL Server分页存储过程
本文主要谈谈Java调用SQL Server分页存储的过程,其返回是多个结果集,只要呈现形式是代码,文字不多,简单易懂。
SQL存储过程:
USE [Db_8za8za_2] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Description: <Description,,通用分页存储过程> -- ============================================= ALTER PROCEDURE [dbo].[paging ] -- Add the parameters for the stored procedure here --传入参数 @SqlStr nvarchar(4000), --查询字符串 @CurrentPage int, --第N页(当前页数) @PageSize int --每页行数 AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; --定义变量 DECLARE @CursorId int --CursorId是游标的id DECLARE @Rowcount int --总记录(行)数 DECLARE @pageCount int --总页数 -- Insert statements for procedure here EXEC sp_cursoropen @CursorId output,@SqlStr, @Scrollopt=1,@Ccopt=1,@Rowcount=@Rowcount OUTPUT SET @pageCount=CEILING(1.0*@Rowcount/@PageSize)--设置总页数 SELECT @pageCount AS 总页数,@Rowcount AS 总行数,@CurrentPage AS 当前页 --提示页数 IF(@CurrentPage>@pageCount)--如果传入的当前页码大入总页码数则把当前页数设为最后一页 BEGIN SET @CurrentPage = @pageCount--设置当前页码数 END IF(@CurrentPage<=0)--如果传入的当前页码大入总页码数则把当前页数设为第一页 BEGIN SET @CurrentPage = 1--设置当前页码数 END SET @CurrentPage=(@CurrentPage-1)*@PageSize+1 --设置当前页码数 EXEC sp_cursorfetch @CursorId,16,@CurrentPage,@PageSize EXEC sp_cursorclose @CursorId --关闭游标 SET NOCOUNT OFF END
Java调用储存过程:
相关推荐
  Omega    2020-08-16  
   zjyzz    2020-08-16  
   minggehenhao    2020-07-28  
   zhaojp0    2020-06-27  
   zjuwangleicn    2020-06-25  
   wenjieyatou    2020-06-17  
   liaomingwu    2020-06-16  
   hungzz    2020-06-16  
   muzirigel    2020-06-14  
   gsmfan    2020-06-14  
   ncomoon    2020-06-14  
   xiaobaif    2020-06-13  
   Rain    2020-06-12  
   hanshangzhi    2020-06-12  
   talkingDB    2020-06-12  
   IBMRational    2020-06-09  
   snowguy    2020-06-01