File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes to retrive the last row Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "to retrive the last row" Watch "to retrive the last row" New topic
Author

to retrive the last row

bakiyalakshmi dhanraj
Greenhorn

Joined: Nov 02, 2007
Posts: 24
hi all,
how to retrieve the last added row,without using query.there is one keyword. can any one tel me the keyword for that one.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

you can use Last() method to moves your cursor to the last row in the ResultSet object. see Java Doc here.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

Do you want any records other than the last? If you just want the last record I'd reorganize the query so that it selects only a single record.


My Blog: Down Home Country Coding with Scott Selikoff
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Originally posted by Muhammad Saifuddin:
you can use Last() method to moves your cursor to the last row in the ResultSet object. see Java Doc here.
The last row in a Resultset object might not be the last added row.
The requestor will first have to define the criterea that determine the last added row.
Using the highest auto-generated record ID might not help, because several databases pool sequence IDs, and do not guarantee that these IDs are used in order.


OCUP UML fundamental and ITIL foundation
youtube channel
Kevin Smither
Ranch Hand

Joined: Oct 22, 2007
Posts: 30
just write the query appropriately depending on your database design, although why you would want to do this is beyond me...it's better to use exact criteria rather than being arbitrary such as "last updated row"
[ March 26, 2008: Message edited by: Kevin Smither ]
bakiyalakshmi dhanraj
Greenhorn

Joined: Nov 02, 2007
Posts: 24
In one interview there ask this question,that's why i ask u
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

Originally posted by bakiyalakshmi dhanraj:
In one interview there ask this question,that's why i ask u

Sometimes an interviewer wants to see how you think rather than an exact answer. It could be they were looking to see if you would suggest a better design.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
Consider Paul's rocket mass heater.
 
subject: to retrive the last row