Guest User

Untitled

a guest
Jun 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. SELECT * FROM MyTable
  2. LIMIT 0, 100
  3.  
  4. // get a ResultSet from some query
  5. ResultSet results = ...
  6. if (count > 0) {
  7. results.setFetchSize(count + 1);
  8. results.setFetchDirection(ResultSet.FETCH_FORWARD);
  9. results.absolute(count * beginIndex);
  10. }
  11. for (int rowNumber = 0; results.next(); ++rowNumber) {
  12. if (count > 0 && rowNumber > count) {
  13. break;
  14. }
  15. // process the ResultSet below
  16. ...
  17. }
  18.  
  19. CREATE PROCEDURE Objects_GetPaged
  20. (
  21. @sort VARCHAR(255),
  22. @Page INT,
  23. @RecsPerPage INT,
  24. @Total INT OUTPUT
  25. )
  26. AS
  27. SET NOCOUNT ON
  28.  
  29. --Create a temporary table
  30. CREATE TABLE #TempItems
  31. (
  32. id INT IDENTITY,
  33. memberid int
  34. )
  35.  
  36. INSERT INTO #TempItems (memberid)
  37. SELECT Objects.id
  38. FROM Objects
  39. ORDER BY CASE @sort WHEN 'Alphabetical' THEN Objects.UserName ELSE NULL END ASC,
  40. CASE @sort WHEN 'Created' THEN Objects.Created ELSE NULL END DESC,
  41. CASE @sort WHEN 'LastLogin' THEN Objects.LastLogin ELSE NULL END DESC
  42.  
  43.  
  44. SELECT @Total=COUNT(*) FROM #TempItems
  45.  
  46. -- Find out the first and last record we want
  47. DECLARE @FirstRec int, @LastRec int
  48. SELECT @FirstRec = (@Page - 1) * @RecsPerPage
  49. SELECT @LastRec = (@Page * @RecsPerPage + 1)
  50.  
  51.  
  52. SELECT *
  53. FROM #TempItems
  54. INNER JOIN Objects ON(Objects.id = #TempItems.id)
  55. WHERE #TempItems.ID > @FirstRec AND #TempItems.ID < @LastRec
  56. ORDER BY #TempItems.Id
  57.  
  58. CachedRowSet crs = new CachedRowSetImpl();
  59. crs.setMaxRows(20);
  60. crs.setPageSize(4);
  61. crs.populate(rsHandle, 10);
Add Comment
Please, Sign In to add comment