java调用SqlServer分页存储过程的,返回多个结果集
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
ENDUSE [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
ENDJava调用储存过程:
Java代码
package test;
import java.sql.*;
public class Study3 {
private Connection con;
public ResultSet rs;
private CallableStatement callsta;
private String use = "sa";
private String pwd = "sa";
public Study3() {
try {
// 连
补充:软件开发 , Java ,