• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fill java.awt.Choice from a List generated by a resultSet

 
Ron Ingram
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to drill into a selection on a swing application. I'm calling the database running a select statement and putting the resultset into a List. From there, I want to get the value in index(3) for each iteration of the List. The problem is, I get only the first value correctly, but not the next iterations...

Can someone please review the code and let me know what I'm doing wrong? Thanks!

ActionPerformed..


Database Helper


 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ron,

Do you get an exception? If so, please post the stacktrace.
 
Ron Ingram
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still working on it.. No exception. Just doesn't work right. I get the same value 3 times...
 
Rob Spoor
Sheriff
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CASE_SELECT returns a list with 11 elements per row; if there are 5 rows it will have 55 elements. That's because you add 11 column values per row.
In control_choiceItemStateChanged you keep getting the 4th element of that list. That's always the same.

I see two approaches:
1) Don't add 11 column values per row. Instead, create a new class for containing the values of each row. In CASE_SELECT you then create one instance for each row, and add that instance to the List. In control_choiceItemStateChanged you then get each element of the List, and get the right value from that element.

2) First get the 4th element (get(3)). Then get the 15th (get(14)). Next is the 26th (get(25)). Etc. In other words, increase the index with 11 each time.
 
Ron Ingram
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,

Thanks for the tip. Would you mind explaining the first recommendation for me? I'm trying to go that route.. But still no prevail. If I statically call each column needed by adding 11, it works fine. The problem is that the result will change so I need a populated dynamic way to get the 3rd element in each iteration..

Ron
 
Rob Spoor
Sheriff
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course "MyClass" isn't a good name, so replace it with something else. I also added a bit more generics.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic