aspose file tools*
The moose likes Beginning Java and the fly likes Invoking a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Invoking a method" Watch "Invoking a method" New topic
Author

Invoking a method

John Paul Hoey
Greenhorn

Joined: Apr 15, 2012
Posts: 25
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

Joined: Apr 15, 2012
Posts: 25
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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.


The quieter you are, the more you are able to hear.
John Paul Hoey
Greenhorn

Joined: Apr 15, 2012
Posts: 25
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

Joined: Jun 19, 2010
Posts: 825
    
    5

It's Kemal and it's a ResultSet, not Record Set.

You're welcome!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invoking a method