Oracle and MySql paging examples

Source: Internet
Author: User

Triplicate

Select mbid00, mbmc00, llurl0, cfwz00, mbsltp, sycs00, lrsj00 from (
Select mbid00, mbmc00, llurl0, cfwz00, mbsltp, sycs00, lrsj00, rownum as con from (
Select * from JZ_MBXXB0 where 1 = 1 and lbid00 =
'123'
Order by lrsj00)
Where rownum <=
10
) Where con> =
1

In hibernate + Mysql

  1. /** 
  2. * Paging Query 
  3. */
  4. @ SuppressWarnings("Unchecked")
  5. PublicList doSearch (PageDao pageDAO,Final IntPageSize,
  6. FinalString name00)ThrowsException {
  7. List list =NewArrayList ();
  8. StringBuffer SQL =NewStringBuffer (
  9. "From Book B where B. name00 LIKE '%");
  10. SQL. append (name00 );
  11. SQL. append ("% '");
  12. FinalString typeSql =NewString (SQL );
  13. // Set the number of entries displayed on each page
  14. PageDAO. setPagesize (pageSize );
  15. IntPagesize = pageDAO. getPagesize ();
  16. // Obtain the total number of records
  17. List count = (listmediahibernatetemplate.exe cute (
  18. NewHibernateCallback (){
  19. PublicObject doInHibernate (Session session)
  20. ThrowsHibernateException, SQLException {
  21. Query q = session. createQuery (typeSql );
  22. // Q. setFirstResult (0 );
  23. // Q. setMaxResults (2 );
  24. List ss = q. list ();
  25. ReturnQ. list ();// No null is returned even if no data is found. Only isEmpty can be used.
  26. }
  27. }
  28. );
  29. PageDAO. getRsCountForSQL (count. size ());
  30. // Obtain the total number of pages
  31. PageDAO. GetPageCount ();
  32. // Obtain the current page
  33. Final IntCurrpage = pageDAO. GetCurrentPageForRequest ();
  34. // Set the toolbar type
  35. String pool = pageDAO. pagetool (PageDao. Text );
  36. // System. out. println (pageDAO. getParamUrl ());
  37. List <BookDTO> dt =NewArrayList <BookDTO> ();
  38. List rs = (listpolichibernatetemplate.exe cute (
  39. NewHibernateCallback (){
  40. PublicObject doInHibernate (Session session)
  41. ThrowsHibernateException, SQLException {
  42. Query q = session. createQuery (typeSql );
  43. Q. setFirstResult (currpage-1) * PageSize );
  44. Q. setMaxResults (pageSize );// Currpage *
  45. List ss = q. list ();
  46. ReturnQ. list ();// No null is returned even if no data is found. Only isEmpty can be used.
  47. }
  48. }
  49. );
  50. For(Iterator it = rs. iterator (); it. hasNext ();){
  51. Object obj = it. next ();
  52. BookDTO dto =NewBookDTO ();
  53. BeanUtils. copyProperties (obj, dto );
  54. Dt. add (dto );
  55. }
  56. // Session. setAttribute ("pagedto", pageDAO );
  57. List. add (0, Dt );
  58. List. add (1, Pool );
  59. ReturnList;
  60. }
  • 1
  • 2
  • Next Page

Related Article

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.