Paul Clapham wrote:Welcome to the Ranch!
So... you have one JTable and you want to put data from two database tables into it? Then it seems to me you need to join the two database tables, no? I see you already used the word "join" in your post, but your database query doesn't join the two tables.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Tim Holloway wrote:Helpful hint: use try-with-resources on your Connection logic. It makes things simpler, tidier, and more foolproof.
You may be sourcing from multiple database tables, but the JTable doesn't talk to the database directly - it's part of the Model/View/Controller architecture, where the JTable is the View clas and it's actually getting (and possibly setting) data from its associated Model. You define a Model class and populate it from the database, and there's nothing magic about a Model getting data from multiple sources as long as the populate logic puts everything in the proper places.
Paul Clapham wrote:It's even more complicated when you don't know what columns are in the first table. I'm guessing that you would be joining on student-school-id and subject-code, but without knowing the contents of the first table it's just a guess. Your JTable headers suggest that subject-code is there, anyway.
Carey Brown wrote:Did you design those tables yourself? It seems like some normalization is missing, 'subject_title' for instance, is the really a key or do the values in the two tables just happen to be the same?
Paul Clapham wrote:No. Your problem is that your JTableModel needs to contain data which comes from joining the two tables. That means that your SQL query must join the two tables appropriately and return the 6 columns which need to go into the JTableModel.
Jomar Reyes wrote:But how can I do it in
if the query to fetch the data from the second db table must use the data fetched from the first db table? either of these two. It should be something like this SELECT * FROM (table2) WHERE subject_code = '"++'";
Carey Brown wrote:
I think that's it. I'm a little rusty.
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|