File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes JDBC Query Help!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Query Help!!!!!" Watch "JDBC Query Help!!!!!" New topic

JDBC Query Help!!!!!

Koh Khai Huat
Ranch Hand

Joined: Aug 05, 2005
Posts: 100
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 ="Select * from LockerInfo");
while (

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

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

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


if (!WorkHard){
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 29249

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Koh Khai Huat
Ranch Hand

Joined: Aug 05, 2005
Posts: 100
thank you

i will take note of that

I agree. Here's the link:
subject: JDBC Query Help!!!!!
Similar Threads
Datasource Connection
Result set
Java Package RUNTIME error
Invalid handle
Updating Problem