Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking a method

 
John Paul Hoey
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's Kemal and it's a ResultSet, not Record Set.

You're welcome!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic