This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 3749
    
  10

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.


[OCA 8 Book] [Blog]
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2551
    
  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
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: 32636
    
215

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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
Consider Paul's rocket mass heater.
 
subject: to retrive the last row
 
It's not a secret anymore!