logic problem
while going through a resultset, I get a bunch of records with many fields including date objects. I would like to display only the record with the latest date ? I'm really having trouble coding this.
Thank you
Web Development
while going through a resultset, I get a bunch of records with many fields including date objects. I would like to display only the record with the latest date ? I'm really having trouble coding this.
Thank you
Hi,
I suggest you simply sort the resultset.
http://java.sun.com/docs/books/tutorial/collections/algorithms/index.html
(remove spaces from the above URL)
Then choose the first...
Alternatively, you could set an indexed view up in the database (depending on what you're actually doing...) and simply retrieve the first record of that view.
Cheers,
Tim.
by ururya
by nise_k
Hi,
There are two methods :
1. Optimise the query itself, to get the record only with the max Date.
e.g SELECT * FROM TABLE WHERE ENTRY_DATE = (SELECT MAX(ENTRY_DATE) FROM TABLE)
2. Make a Function which compares two Dates and returns 1, 0 or -1, for First Date greater, First and Second Date are Same or First Date lesser, correspondingly .
e.g. int compareDate(date1, date2)
Then store the Dates you fetch from the ResultSet and compare the Current Date with the last Max Date read. If new date is greater, then store this date as the Max Date, keep comparing like this. Then you can find the appropriate record.
Bye.
Nise
by ururya
by ururya
This discussion is closed to new replies.
Sort by Trending