Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:40:50+00:00 2026-06-13T22:40:50+00:00

I have an auto generated timestamp that is created each time a record is

  • 0

I have an auto generated timestamp that is created each time a record is inserted or updated in a mysql table. Is there a way to return this timestamp in a way similar to how I would use a keyholder to return a newly created id?

KeyHolder keyHolder = new GeneratedKeyHolder();
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

//Insert Contact
jdbcTemplate.update(new PreparedStatementCreator() {
    @Override
    public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
        PreparedStatement preparedStatement = connection.prepareStatement(SQL_ADD, Statement.RETURN_GENERATED_KEYS);
        preparedStatement.setString(1, contact.getFirstName());
        preparedStatement.setString(2, contact.getLastName());
        preparedStatement.setInt(3, contact.getOrganizationId());
        preparedStatement.setString(4, contact.getType());
        preparedStatement.setInt(5, contact.getUserId());
        return preparedStatement;
        }   
}, keyHolder);
//Use keyholder to obtain newly created id
contact.setId(keyHolder.getKey().intValue());

Is there some way to also return the new timestamp without having to requery the table? I have been looking for ways to return it along with the id as a key in the keyholder, but it doesn’t seem to be returned as a key?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:40:51+00:00Added an answer on June 13, 2026 at 10:40 pm

    There are few options for solving this issue on the MySQL database server side. You could start with creating a TRIGGER on the table. As TRIGGER has a restriction and cannot return data, you can set the TIMESTAMP value to a variable:

    DEMILITER //
    CREATE TRIGGER ai_tbl_name AFTER INSERT ON tbl_name
    FOR EACH ROW
    BEGIN
    
    SET @TimeStamp = NEW.timestamp_column;
    
    END;//
    DELIMITER ;
    

    To retrieve this timestamp value, run the following command:

    SELECT @TimeStamp;
    

    Since the variables are stored in the memory, there will be no need to open any tables again.

    You go even further. You could create a STORED PROCEDURE in MySQL to automate all the above (sample code, as I do not know your table’s details):

    DELIMITER //
    DROP PROCEDURE IF EXISTS sp_procedure_name //
    CREATE PROCEDURE sp_procedure_name (IN col1_val VARCHAR(25),
                                        IN col2_val VARCHAR(25),
                                        IN col3_val INT)
    BEGIN
        INSERT INTO tbl_name (col1, col2, col3)
        VALUES (col1_val, col2_val, col3_val);
    
        SELECT @TimeStamp;
    END; //
    DELIMITER ;
    

    You can run this procedure with the following code:

    CALL sp_procedure_name(col1_val, col2_val, col3_val);
    

    As I’m not familiar with the Java, you’ll need to finish it up with your side of code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridivew with auto-generated fields, whenever there is a new set of
We have discovered that one of our auto generated assemblies is throwing a StackOverflowException
I have a constructor (for an auto generated class) that has 255 paremeters. Using
I have a domain object that has been auto generated for me by MyGeneration.
I have a bunch of PHP code that is auto-generated and it puts all
I have an application that displays the data from 3 xml files (auto generated
I have a table with a auto-generated primary key and a DateTime field. And
I have to auto generate timestamp when I am creating a new record and
I have a class that was auto-generated by the XSD tool in visual studio
We have a display message that is auto-generated by default, but may be overridden

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.