• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Invoking a method

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a query which im hoping someone will be able to answer for me please.

Within the main method i have the following two statements:



As you can see from the above code, i am using the same object (dbCon) to invoke the same method, that takes a jComboBox object and adds items to a list from a database.

Here is the code for the method im invoking:



However my problem is that the second combo box is not getting populated with the data i want to add from the database - only the first combobox is being populated with the required data. On the other hand, when i change the combo boxes around within the first set of statements, DispEndCombo2 gets populated whereas DispEndCombo1 doesnt.

What im wondering is why the second statement is not working for populating the combobox - do i need to use different objects (i.e. dbCon and another) for this to work?

I thought that the same object could be used here however i could be wrong.

Hope this makes sense

Thanks in advance

John Paul
 
John Paul Hoey
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Ok i got this to work by passing the two combo boxes as parameters at the same time rather than doing it separately, i also had to change the method i was invoking to handle this.

So the following works:





However, im still confused as to why the first version didnt work - anyone got any ideas?

Thanks

John Paul
 
Bartender
Posts: 825
5
Python Ruby Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the problem is in the fact that your result set (if disEndRS is a result set, I think it is) is an instance variable, so in fact you are using the same result set throughout your class.

With that being said, the problem is obvious - at line 6 of your method, you are moving the cursor to the next row, until there are no more rows in the result set. With one combo box being populated, invoking the same method again for another combo box doesn't enter the while loop at all because the cursor is already at the end, so this.disEndRS.next() returns false.
 
John Paul Hoey
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kemel,

Thanks for your response.

Your answer makes perfect sense regarding the Record Set and its something ill bear in mind going forward with my programming

Thanks again

John Paul

 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's Kemal and it's a ResultSet, not Record Set.

You're welcome!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic