当java中的DB具有相同的id号时,如何在同一行中向jtable添加行? [英] How do I add rows to jtable in same line when it has same id number from DB in java?

查看:69
本文介绍了当java中的DB具有相同的id号时,如何在同一行中向jtable添加行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在DB中有表,我需要在java中的JTable中向表中添加行,我是成功添加这些行但是我需要在JTable中保持每个具有相同id的值在同一行中。

如何在不指定具体数字的情况下查看项目是否具有相同的ID号?我的意思是没有id = 1等等。 ?



我的尝试:



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:

引用:

我的数据库表看起来像



frequent_set_id ----- item_name

1 --------------------------黄油

1 ---------- ----------------油

1 ------------------------ - 苹果

2 ------------------------- cookies

2 --- ----------------------- orange







my DB table look like

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



Quote:





任何帮助请。



any help please .

推荐答案

每条记录必须有它的赢取ID才能唯一识别它。您将现有的ID列视为表的主键,实际上它是另一个表中的外键。



解决方案非常简单。在表格中添加新的标识列。

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


这篇关于当java中的DB具有相同的id号时,如何在同一行中向jtable添加行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆