Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT * FROM MyTable
- LIMIT 0, 100
- // get a ResultSet from some query
- ResultSet results = ...
- if (count > 0) {
- results.setFetchSize(count + 1);
- results.setFetchDirection(ResultSet.FETCH_FORWARD);
- results.absolute(count * beginIndex);
- }
- for (int rowNumber = 0; results.next(); ++rowNumber) {
- if (count > 0 && rowNumber > count) {
- break;
- }
- // process the ResultSet below
- ...
- }
- CREATE PROCEDURE Objects_GetPaged
- (
- @sort VARCHAR(255),
- @Page INT,
- @RecsPerPage INT,
- @Total INT OUTPUT
- )
- AS
- SET NOCOUNT ON
- --Create a temporary table
- CREATE TABLE #TempItems
- (
- id INT IDENTITY,
- memberid int
- )
- INSERT INTO #TempItems (memberid)
- SELECT Objects.id
- FROM Objects
- ORDER BY CASE @sort WHEN 'Alphabetical' THEN Objects.UserName ELSE NULL END ASC,
- CASE @sort WHEN 'Created' THEN Objects.Created ELSE NULL END DESC,
- CASE @sort WHEN 'LastLogin' THEN Objects.LastLogin ELSE NULL END DESC
- SELECT @Total=COUNT(*) FROM #TempItems
- -- Find out the first and last record we want
- DECLARE @FirstRec int, @LastRec int
- SELECT @FirstRec = (@Page - 1) * @RecsPerPage
- SELECT @LastRec = (@Page * @RecsPerPage + 1)
- SELECT *
- FROM #TempItems
- INNER JOIN Objects ON(Objects.id = #TempItems.id)
- WHERE #TempItems.ID > @FirstRec AND #TempItems.ID < @LastRec
- ORDER BY #TempItems.Id
- CachedRowSet crs = new CachedRowSetImpl();
- crs.setMaxRows(20);
- crs.setPageSize(4);
- crs.populate(rsHandle, 10);
Add Comment
Please, Sign In to add comment