简体   繁体   中英

Get all automatically generated values after insert

After inserting a new row into a database table it is possible to get the value of the generated primary key like this:

PreparedStatement statement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
ResultSet keys = statement.getGeneratedKeys();

But how can I retrieve other automatically generated values that are not keys. Lets say my table definition looks like this:

CREATE TABLE foo (
    id INT PRIMARY KEY AUTO_INCREMENT,
    changed TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

Is it possible to get the value of the column changed without the need to query the database again with the returned primary key?

no, data change statements INSERT, UPDATE do not return values of the fields changed/inserted. You can ask for the last key but even that is an additional DBMS call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM