Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Total no of Records In DataBase

 
Neeraj jain
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • 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
 
K. Tsang
Bartender
Posts: 3457
14
Android Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Mahender Parkipandla
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solutions are in our own How-To: Pagination Or Paging.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic