Computer problems,Computer help
*AX SOFT>>>Programming & Design

In JSP I want to print out my database entries with the newest first?


So basically at the moment I have them printing out in order from first to last, so the oldest entries actually get printed out first. I am looking to print out the last entries first.

The ResultSet I am working with is SELECT * FROM ARTICLE.

With each entry I am printing out there are multiple fields so I am unable to just put each entry into an array.

Any ideas on how to print the entries out in the reverse order. Is there a variation on rs.next() or something?

Order them in the DB query. Instead of

SELECT * FROM ARTICLE

Use something like

SELECT * FROM ARTICLE ORDER BY Date DESC

If you don't have a Date column use what ever column denotes when it went into the database. If you have an auto-increment value, that will work. The DESC keyword makes it work in descending order. This way you don't have to change the logic in your code, the recordset object will have the data in the right order already, so when you .next() through it, it'll be in reverse order from newest to oldest.

Just so you're aware of it, the order in which records are stored in a database is not guaranteed, so the most recent entry can be the first one physically, the last one or somewhere in the middle. That's why you need the ORDER BY clause, and a field to order by.

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • In Java, how do you outline a Polyline?

    you could try drawing the line twice. first in black with width 2 pixels and then in green with width 1 pixel.

    ...
  • How much to charge for making an ecommerce website for a small business?

    concentrate on the design work, do a mock up or a layout first, and get their interest. Give them a full list of all the functions.... Don't focus/talk on price, focus on what you will be of...

  • How do i fix this "line b problem parsing xml:'null" is null or not an object"?

    I guess you use AT&T. You need to report this problem to them, it is a bug in their JavaScript and there's nothing you can do about it apart from report it to them.

    ...
  • Is there a difference?

    barrel size is different by 2 inches.. the eight inch comes with pellets

    ...
  • What is the best tutorial, book, or e-book to use to learn as much about using Autodesk Maya 8 from scratch?

    ...

  • What do you think about samples packages like this?

    They save A LOT of time. Some of them are not very good, but you sometimes find exactly what you wanted.

    ...
  • Need help on making webpage?

    "...to take u to another place on my page." The standard link tags, as given already, will not take you to another place on your page. There are different types of links that will lin...

  • Somebody help?!?

    The guy used Flash 8. He just took screenshots of Flash 8 and pasted them inside the program to manipulate them.

    ...
  •  

    Categories--Copyright/IP Policy--Contact Webmaster