Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Query Help!!!!!

 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

i need help in query the database using JDBC. Wen i query the database the result return to me is not in order how do u get the database to return u the data in ascending order

this is the code i use to query the database :

try{rs = ConnectionDB.st.executeQuery("Select * from LockerInfo");
while (rs.next())
{

result[l] = rs.getString("Used");

lockerID[l] = rs.getString("LockerID");

System.out.println("Result = " + result[l] + " LockerID = " + lockerID[l]);
l ++;
}
}

regards
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34681
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Koh,
Welcome to JavaRanch!

SQL has a clause called order by, which allows you to specify what to sort the result by. So you could do "Select * from LockerInfo order by lockerid" to sort ascendingly or "Select * from LockerInfo order by lockerid desc" to sort descendingly.

Note that we have a forum at the top of the page for JDBC/SQL questions. Feel free to ask database questions there in the future.
 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you

i will take note of that

regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic