• 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

iterating through ResultSet

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there. I am running a simple SQL query that returns a result set containing two columns. A sample set of results appears as follows:

CFCC ID
D43 73
D43 78
D43 87
D44 65
D65 102
D65 107
D65 111
D65 115
D85 77
... ...

What I would like to do is for every distinct value encountered in the first column, create an object and set an array/vector of size equal to the number of values in the second column associated with that first column value. For example, an object called 'D43_object' that has a vector of size 3 containing the 3 ids associated with cfcc 'D43'. My attempt at coding this is as follows:



I know why my code does not work but I do not know how to go about altering it so that objects are instantiated correctly and how I can create new objects only for certain rows in the result set and not for every row in the result set. Can anybody show me how I might fix this. Thnaks a lot, Joe
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you considered the idea of using a Hashtable with cfcc as the key and the vector of Ids as a value? This way you don't have to worry about the order of the the cfcc's being returned and I think you'd have to do less checking.
 
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
Joe,
Make sure you have an order by clause in your SQL statment so the cfcc's are returned in order.

The idea looks fine. Although "that has a vector of size 3 " is more of an implicit requirement. You will wind up with a Vector with three elements in it. But you don't need to know there are three before you start out.




The only thing I don't see is the collection you are storing all the LayerFeature objects in.
 
joew weakers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeanne, Denise. Thanks a lot for your replies. Denise, I have not tried using Hsahtables just yet but I may use them in the future. Jeanne, I did as you suggested but I am still encountering the following error:

variable landmark_ids might not have been initialized

The code is as you specified:



Its kind of like the error I had initially. Have you any ideas. Cheers, joe
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change this:

To this:

...initialised.
 
reply
    Bookmark Topic Watch Topic
  • New Topic