在jtable中显示最后修改的sql表 [英] Display Last Modified Sql Table in jtable

查看:104
本文介绍了在jtable中显示最后修改的sql表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java编写一个程序,对SQL进行查询并在jtable中显示结果,我的问题是如果我执行插入,删除或更新操作,我希望我的jtable显示已修改的sql表,有什么功能吗? 这是我执行查询的方法:

I'm making a program in java that makes queries into SQL and show the result in a jtable, my problem is if i do Insert, delete or update i want my jtable to show the sql table that was modified, is there any function for that? This is my method to execute the query:

  public void executequery() {

            try {
                String userQuery = Query.getText();
                Statement statement;
                statement = conn.createStatement();
                statement.execute(userQuery);
                ResultSet rs = statement.executeQuery(userQuery);
                //in case of a instert, delete or update i want to show
                //the modified sql on my jtable
                table.setModel(DbUtils.resultSetToTableModel(rs));
                rs.close();
                statement.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

推荐答案

我有很多表

您可以使用名为lastModified的外部表,并在每个插入更新删除操作中使用db触发器,并在上述操作中更新表.

you can use an external table called lastModified and use a db trigger in every insert update delete operation and update the table on above operations.

现在映射一个具有唯一ID的表名,并在每个操作中更新记录lastUpdatedTime列.

now map a table name with a unique id and update the record lastUpdatedTime column in every operation.

获取按时间顺序排列的第一条结果记录.

get the first record of result ordered by time.

这将是最后更新的表.

表格格式

| id | table_name | last_updated_time |

这篇关于在jtable中显示最后修改的sql表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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