如何在更新数据库时自动更新JTable数据?

时间:2022-03-14 07:25:51

How can I update my JTable data automatically when my database is updated?

如何在更新数据库时自动更新JTable数据?

Thanks.

1 个解决方案

#1


Your JTable data model will somehow have to determine whether your database has changed.

您的JTable数据模型将以某种方式确定您的数据库是否已更改。

There's no standard way of feeding this info direct from a SQL database to a table model. Most likely you will have to poll the database and discover this info for yourself (in a polling thread?)

没有标准的方法可以直接从SQL数据库向表模型提供此信息。您很可能需要轮询数据库并为自己发现此信息(在轮询线程中?)

Depending on the complexity of the query required to populate the table, and the quantity of the data in the table, you can poll to get the complete data set back and rebuild the table if necessary, or poll for the latest updated row, and then issue a query for the complete dataset if this has changed.

根据填充表所需的查询的复杂性以及表中数据的数量,您可以轮询以获取完整的数据集并在必要时重建表,或轮询最新更新的行,然后如果已更改,则发出完整数据集的查询。

Depending on whether you're using particular frameworks or SQL database products, there may be more product-specific answers to this question.

根据您使用的是特定框架还是SQL数据库产品,可能会有更多针对此问题的产品特定答案。

#1


Your JTable data model will somehow have to determine whether your database has changed.

您的JTable数据模型将以某种方式确定您的数据库是否已更改。

There's no standard way of feeding this info direct from a SQL database to a table model. Most likely you will have to poll the database and discover this info for yourself (in a polling thread?)

没有标准的方法可以直接从SQL数据库向表模型提供此信息。您很可能需要轮询数据库并为自己发现此信息(在轮询线程中?)

Depending on the complexity of the query required to populate the table, and the quantity of the data in the table, you can poll to get the complete data set back and rebuild the table if necessary, or poll for the latest updated row, and then issue a query for the complete dataset if this has changed.

根据填充表所需的查询的复杂性以及表中数据的数量,您可以轮询以获取完整的数据集并在必要时重建表,或轮询最新更新的行,然后如果已更改,则发出完整数据集的查询。

Depending on whether you're using particular frameworks or SQL database products, there may be more product-specific answers to this question.

根据您使用的是特定框架还是SQL数据库产品,可能会有更多针对此问题的产品特定答案。