I have stored various records in the MySql database \"orkut\". Now I want to sort that database through a java program. I have connected to the database through the jdbc driver.
Don't try to sort this through Java--you'll kill yourself trying. SQL has an order by
clause that does exactly this. Here's the SQL:
select
number,
sr_no
from
tbl
order by
number desc
Also note that you cannot have a permanently sorted database. The way that the data is stored does not lend itself to being stored in whatever order you choose. You should never count on the order of a database to be the same, unless you use an order by
in your query.
as eric told you can't have a permanently sorted database. But if you want to execute this query on a large dataset very frequently then you can do indexing supported by various database.
It will speedup your searching and sorting for a particular key.