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