Display Last Modified Sql Table in jtable

谁说我不能喝 提交于 2019-12-25 08:17:12

问题


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();
            }

        }

回答1:


I you have large number of tables

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.

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.

that will be the last updated table.

table format

| id | table_name | last_updated_time |



来源:https://stackoverflow.com/questions/40561095/display-last-modified-sql-table-in-jtable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!