• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC Query Help!!!!!

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you

i will take note of that

regards
reply
    Bookmark Topic Watch Topic
  • New Topic