aspose file tools*
The moose likes JDBC and the fly likes Total no of Records In DataBase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Total no of Records In DataBase" Watch "Total no of Records In DataBase" New topic
Author

Total no of Records In DataBase

Neeraj jain
Ranch Hand

Joined: Jun 18, 2013
Posts: 83
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

Joined: Sep 13, 2007
Posts: 1977
    
    7

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7
Neeraj jain
Ranch Hand

Joined: Jun 18, 2013
Posts: 83
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

Joined: Dec 28, 2009
Posts: 17
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

Joined: Jun 18, 2013
Posts: 83
yes i am also implementing it thats why i need this can you tell me the solution of this problem
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2477
    
    7

Solutions are in our own How-To: Pagination Or Paging.


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Total no of Records In DataBase
 
Similar Threads
Rownum for large rownumbers
retrieve nth salary thru optimized sql query
how to get details without querying full table ResultSetMetaData
Selecting random rows
mysql limit and oracle rownum to limit resultset