Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi all , i have table in DB and i need to add rows to table in my JTable in java , i was add these rows successfully but i need to keep each values which have same id in same line in JTable .
how i see if items have same id number without assign the specific number ? i mean without id = 1 and so on . ?

What I have tried:

Quote:
my DB table look like

frequent_set_id ----- item_name
1 -------------------------- butter
1 -------------------------- oil
1 -------------------------- apple
2 ------------------------- cookies
2 --------------------------orange



Quote:


any help please .
Posted
Updated 25-Apr-17 10:31am
v2

1 solution

Each record has to have it's won ID to uniquely identify it. You're treating your existing ID column as a primary key for the table when it is, in fact, a foreign key into another table.

The solution is pretty easy. Add a new identity column to the table.
ID    Frequency_Set_Id    Item_Name
 1            1           Butter
 2            1           Oil
 3            1           Apple
 4            2           Cookies
 5            2           Orange
 
Share this answer
 
Comments
Member 13152044 25-Apr-17 16:35pm    
actually item_Name is a item_id and its foreign key from table ITEM , but i wrote it in this way to understand my problem .
Dave Kreskowiak 25-Apr-17 16:40pm    
No, you actual made it more confusing. What is the EXACT layout of this table, with example data?
Member 13152044 25-Apr-17 17:05pm    
frequent_set_id -- Item_id
1 ---------- 1
1 ---------- 2
1 --------- 5
2 --------- 7
2 --------- 9

this is my exact table . and Item_id is foreign key refers to table ITEM , i can extract the names of items but my problem in how to see if frequent_set_id same to put them in same line in java table .
Dave Kreskowiak 25-Apr-17 17:29pm    
You're asking how do you retrieve everything that has a frequent_set_id of 1 from that table and consolidate it into a single string? Like ID 1 should be shown as "Butter, Oil, Apple"?
Member 13152044 25-Apr-17 17:40pm    
Yes , but note that i will not write specefic id number for example: see which items has id = 1 and put them together and so on, Because the DB table may have other elements added with new id and my java code not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900