• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Total no of Records In DataBase

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1:->how can i find total no of records in database .?....
2:-> i want to find total no of records then i have to fetch only 5 records at a time so when i am firing a query 2 times such that


ResultSet rs1=st1.executeQuery("select * from "+table); // this ones for finding the total no of records

ResultSet rs=st.executeQuery("SELECT * FROM (SELECT "+table+".*, ROWNUM RN FROM "+table+" WHERE ROWNUM <="+upr +" ORDER BY ID) WHERE RN >" +lwr); // this ones for fetching 5 records at a time here lwr and upr are onlyy variables


now when i execute it i am getting nothin but an error so now please tell me how to resolve it
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For getting all records in a table it's "select count(*) from table". You currently have the actual data returned.

For the fetching, depends on what DB you use. If you use say MySQL, you can use the LIMIT clause. If you use Oracle then rownum can be used but can't guarantee if the data order is the same every time.

You most likely need to store the from and to variables in some request attributes or something.
 
Neeraj jain
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
now i am getting an Exhausted Result Set exception ..............

i fetched the total no of records then when i am trying to fetch the 5 records i am getting an ExhaustedResultSetException
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This concept is called Pagination.
When there are frequent insertions into a table, then it's difficult get different You have to do order by on set of records to get the data from DB.
Best way is to get the data from DB and display in application in Pagination manner.
 
Neeraj jain
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i am also implementing it thats why i need this can you tell me the solution of this problem
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solutions are in our own How-To: Pagination Or Paging.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic