问题
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