This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Query Help!!!!!" Watch "JDBC Query Help!!!!!" New topic
Author

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 = 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


if (!WorkHard){
System.out.println("Fail!!!");
}
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

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.


[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

regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Query Help!!!!!