If java calls the paging stored procedure, multiple result sets are returned.

Source: Internet
Author: User

SQL code
USE [Db_8za8za_2]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ===================================================== ======
-- Description: <Description, General paging stored procedure>
-- ===================================================== ======
Alter procedure [dbo]. [paging]
-- Add the parameters for the stored procedure here
-- Input parameters
@ SqlStr nvarchar (4000), -- query string
@ CurrentPage int, -- page N (current page number)
@ PageSize int -- number of lines per page
AS
BEGIN
-- Set nocount on added to prevent extra result sets from
-- Interfering with SELECT statements.
Set nocount on;
-- Define variables
DECLARE @ CursorId int -- CursorId is the cursor id
DECLARE @ Rowcount int -- total number of records (rows)
DECLARE @ pageCount int -- total number of pages
-- Insert statements for procedure here

EXEC sp_cursoropen @ CursorId output, @ SqlStr,
@ Scrolopt = 1, @ Ccopt = 1, @ Rowcount = @ Rowcount OUTPUT

SET @ pageCount = CEILING (1.0 * @ Rowcount/@ PageSize) -- SET the total number of pages

SELECT @ pageCount
Total number of AS pages, @ Rowcount AS total number of rows, @ CurrentPage AS current page-page prompt

IF (@ CurrentPage> @ pageCount) -- IF the incoming current page number is larger than the total page number, set the current page number to the last page.
BEGIN
SET @ CurrentPage = @ pageCount -- SET the current page number
END
IF (@ CurrentPage <= 0) -- IF the incoming current page number is larger than the total page number, set the current page number to the first page.
BEGIN
SET @ CurrentPage = 1 -- SET the current page number
END
SET @ CurrentPage = (@ CurrentPage-1) * @ PageSize + 1 -- SET the current page number

EXEC sp_cursorfetch @ CursorId, 16, @ CurrentPage, @ PageSize
EXEC sp_cursorclose @ CursorId -- close the cursor

SET NOCOUNT OFF
END

USE [Db_8za8za_2]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ===================================================== ======
-- Description: <Description, General paging stored procedure>
-- ===================================================== ======
Alter procedure [dbo]. [paging]
-- Add the parameters for the stored procedure here
-- Input parameters
@ SqlStr nvarchar (4000), -- query string
@ CurrentPage int, -- page N (current page number)
@ PageSize int -- number of lines per page
AS
BEGIN
-- Set nocount on added to prevent extra result sets from
-- Interfering with SELECT statements.
Set nocount on;
-- Define variables
DECLARE @ CursorId int -- CursorId is the cursor id
DECLARE @ Rowcount int -- total number of records (rows)
DECLARE @ pageCount int -- total number of pages
-- Insert statements for procedure here

EXEC sp_cursoropen @ CursorId output, @ SqlStr,
@ Scrolopt = 1, @ Ccopt = 1, @ Rowcount = @ Rowcount OUTPUT

SET @ pageCount = CEILING (1.0 * @ Rowcount/@ PageSize) -- SET the total number of pages

SELECT @ pageCount
Total number of AS pages, @ Rowcount AS total number of rows, @ CurrentPage AS current page-page prompt

IF (@ CurrentPage> @ pageCount) -- IF the incoming current page number is larger than the total page number, set the current page number to the last page.
BEGIN
SET @ CurrentPage = @ pageCount -- SET the current page number
END
IF (@ CurrentPage <= 0) -- IF the incoming current page number is larger than the total page number, set the current page number to the first page.
BEGIN
SET @ CurrentPage = 1 -- SET the current page number
END
SET @ CurrentPage = (@ CurrentPage-1) * @ PageSize + 1 -- SET the current page number

EXEC sp_cursorfetch @ CursorId, 16, @ CurrentPage, @ PageSize
EXEC sp_cursorclose @ CursorId -- close the cursor

SET NOCOUNT OFF
END

Java calls the stored procedure:


Java code
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 {
// Connect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.