• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting Data

 
zohreh talebi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I want to sort my database...I know this syntax is true : "SELECT * FROM song ORDER BY nameOfTheSong"

because when I want to sort my data in MySQL it works, but when I call this method it doesn't work. May be I have

used a wrong object or method in my code ... I'm not sure.

public void sortByNameOfTheSong()
{
try
{
Statement stmt = connect.createStatement(ResultSet.TYPE_SCROLL_INSEVSITIVE,
ResultSet.CONCUR_READ_ONLY);
stmt.executeQuery("SELECT * FROM song ORDER BY nameOfTheSong");
}
catch(SQLException sq)
{
logger.info("The table could not be sorted");
}
}

Thanks in advance,
Zohreh
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you log the exception to see what it said?
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the error message to sq.printStackTrace() to see the error. My guess is the error has to do with the query, not the fact that you are trying to sort.

Btw, performing a sorting query DOES NOT sort the database, it just returns you a sorted set of data. Everytime the query is called the database sorting operation is re-performed. You should look into adding an index to the column so that the data can be accessed consistently in a sorted order. This would make calls to retrieve data on this index much (possibly 10000 times) faster.
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you even have an exception? This method could work and you would never know, as you don't do anything with the results of the query. As someone else said that query doesn't permanently sort the table by that column.
 
zohreh talebi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear freinds,

thanks for your anwsers. I think understand my incurrect point.
I had sorted the resultset but it didn't relate to database or my table.Am I true?


thanks
Zohreh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic