This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

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

 
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


 
Ranch Hand
Posts: 176
Mac Chrome 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...
 
Sheriff
Posts: 21836
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Posts: 21836
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
Oh the stink of it! Smell my tiny ad!
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!