Win a copy of Emmy in the Key of Code this week in the General Computing 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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: 21817
104
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: 21817
104
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.
 
Create symphonies in seed and soil. For this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!