• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Using FOR loop to loop in a resultset

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I use a FOR loop for looping a resultset? I need to use FOR loop instead of while (rs.next()) ...
Help me out
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for(int iIndex=0;iIndex<RowCount;iIndex++)
{
rs.next()
}
There are some methods in the API where you can get the row count.
Alternatively you can do a count* using your where condition and you will get the row count although its a bad programming practise hence use the API.
cheers
[ March 26, 2004: Message edited by: Gaurav Jain ]
 
Sheriff
Posts: 67401
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I need to use FOR loop instead of while (rs.next()) ...


Why? That makes little sense.
 
author & internet detective
Posts: 39996
807
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhavan,
I'd be wary of using rowCount because the driver usually has to loop through all the rows to get it. You really should use the while loop though. It's pretty standard.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for loops and while loops are logically equivilant:

[ March 29, 2004: Message edited by: Lu Battist ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
quote:
--------------------------------------------------------------------------------
for (; rs.next(); ) { //everything you had in the while loop}
----------------------------------------------------------------------------
I once try this ,but when I use while (rs.next()) later, it is something wrong.
 
Bear Bibeault
Sheriff
Posts: 67401
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

For loops and while loops are logically equivilant


Regardless. the statement

I need to use FOR loop instead of while


makes no sense.
 
mooooooo ..... tiny ad ....
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic