• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Loop through records to display data in Jtable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day fellow coders.

I am new at coding, I have followed many tutorials but cant find what I am missing, the stupid method: I tried looping through each record of table A once I have the current record then run another select to find what ever data is in table B that matches the table A id.
But I cant get it to work so I abandoned it. The code is too long and the result is messy. See my image I uploaded, I am running it with SQLite, and its should be vry simple but no where do I find sollutions for this issue. Please point me to a place where I can learn how this done.
I have attached an image of my table layout.

Thank you

Mike

jtable_sales.png
[Thumbnail for jtable_sales.png]
 
Bartender
Posts: 6123
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Oxley wrote:I tried looping through each record of table A once I have the current record then run another select to find what ever data is in table B that matches the table A id.


That's what the  INNER JOIN does.
 
Sheriff
Posts: 24635
56
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However the resulting JTable won't look like the nice picture which Mike posted. It's going to look more like this not-so-nice picture:

+ Mike  + 1 +
+ Mike  + 2 +
+ Mike  + 7 +
+ Mike  + 9 +
+ Carol + 4 +
+ Carol + 5 +
+ Carol + 8 +


It's possible that Mike was complaining about that difference. If that's the case then let me point out that it's possible (with some difficulty) to get the nice version of the JTable but the solution doesn't involve collecting the data in a different way.
 
Mike Oxley
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I agree, ALLOT more work, so has anyone tried doing a query in a record set and add another query inside the While (rs.next).
I NEVER give up so it will work eventually ...lol

What I have tried so far is this and it works for the first query but the second gives an error, trying t solve it but its looking good so far.




The error code is:


It is given on line 46 when the code is not //

But my screen looks awesome so far!

Once i Get it I will post it!
Thank you guys for the efforts.


EDIT: IT works, I forgot the second Recordset next section!
update1.png
[Thumbnail for update1.png]
 
Rancher
Posts: 480
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So are you asking how to do an inner join or what?
 
This. Exactly this. This is what my therapist has been talking about. And now with a 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!