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 How to sort rows that are dynamically generated??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to sort rows that are dynamically generated???" Watch "How to sort rows that are dynamically generated???" New topic
Author

How to sort rows that are dynamically generated???

Ravi Kumar
Greenhorn

Joined: Sep 07, 2005
Posts: 24
Hi All,

I am using a form to enter details into the Database. When I sub,it this form I am calling another JSP page. In that page I am connecting with DB and inserting the records into DB and later getting the records from DB and displaying.This thing is working good but what I need is ...the last data entered from the form should display at the end in my table when I am printing. Which is not the case that is happening. I can do a sort on the table but I dont have any ID no. I thought of having a sequence number for the table and as I insert my records increment the sequence number. So that when I print the data back I can sort on the sequnce number. Is this right???

Please help me out.
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Originally posted by Aditya Avula:
I thought of having a sequence number for the table and as I insert my records increment the sequence number. So that when I print the data back I can sort on the sequnce number. Is this right???

Please help me out.


Sequence number, an insert date column, something like that is probably what you need.

Many databases have some to have an auto-generated number; with Oracle it's a SEQUENCE object, with mysql it's AUTOINCREMENT,
http://dev.mysql.com/doc/refman/5.1/en/example-auto-increment.html

Having the database do this means you can have more than one copy of your application updating the database at once. Otherwise you either need to coordinate your applications, or do locking in the database (which slows things down), or tolerate duplicates.

Once you have it, you can use an appropriate ORDER BY in your SELECT statement; the database will very often be able to sort faster than you can in Java.
[ February 16, 2006: Message edited by: stu derby ]
 
wood burning stoves
 
subject: How to sort rows that are dynamically generated???