• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying Information over 2 JTables

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an inner join created between my tables and was just wondering how I manage to split them into 2 tables? I want to have it so when I click Invoice on my first table, it will then display the contents of my Product table. I've messed a round with a lot of code and not managed to get it.

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cavan, welcome to the Ranch!

I'm rather baffled by all of that. Let's start at the beginning.

You have an inner join between your tables -- those are SQL tables. It's badly formed SQL but my question is, why do you need that?

Then you want to split "them" into two tables. The only "them" I can see in the sentence is your SQL tables. Are the two tables you want to get SQL tables, or are they Swing tables? My guess is that they are Swing tables because later you mention clicking on one of them.

So I'd propose starting again by sketching out the GUI. It seems to me that you want a Swing table with Invoices in it. This might be all of the invoices you have, or it might be all invoices for some customer, or something else, but anyway start by deciding what you want to see in that Swing table. To fill the table you'd use code similar to what you just posted... Actually I just noticed that your "Invoice" SQL table includes invoice details (Product and Quantity Ordered), which startled me a bit. I would have expected an "Invoice" table to include invoice number, customer ID, and date, and that there would be an invoice details table. You have unnormalized data there, it looks like. But whatever, you need to decide what you see in your first screen. I assume you want to see just the header information, so your query would need a Group By.

That's probably enough to get started with. Post back when you have more questions.

 
Cavan Phelan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologise for perhaps not making it clear enough. I'm making a Java Gui and the tables I'm looking to make are indeed Swing tables. So I have 3 tables, but I want to show my Invoices and Products table. When you click on an entry in the invoices table, it would also display the products linked to the Invoice table too. So say I click Invoice 3 which has Product id 4, I want the Product table to change to show the product with the id 4 only. I was thinking I needed a inner join in order to do so. At the moment I have a table with my Invoiceid and whatnot but nothing else as of yet. I'm assuming I have to make a separate table for my products but getting them to change in accordance to what's selected is what I don't understand.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to guess at what your Product Swing table contains, so I'm going to assume it only has information about Products, and quite likely only information about one Product. So I'd think you would just query the Product table to get that.

But I'm still confused. In your response you mention "the Product table" and how you want it to change. That's a Swing table I suppose. Then later you said you were assuming you'd have to make a separate table for your products. You said you have a Product table (or at least you implied it) and the query you posted seems to be using a Product SQL table. So I'm confused about what that separate table might be.

As for how to change the contents of an existing Swing table: you build a table model, similar to the code you already posted. Then you call setModel() on the JTable, passing that table model. So when the user clicks on something in the Invoice Swing table, your code is going to query the Product SQL table for the relevant products and build the new table model for the Product Swing table.

Your questions seem to suggest that you think you're just going to execute one query for the whole program, or something like that, but it's not clear to me whether that's the case.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic