In this blog post, I’ll show you how to insert a date and time value into the database.

The date and time is collectively known as a timestamp. JDBC has builtin support for saving and reading timestamps. This support is provided by java.sql.Timestamp.

Let’s assume we have this database table schema below. Make note of the timestamp column called checkout_time.

Saving a Timestamp

You can save a timestamp value with the following code:

Reading a Timestamp

Likewise, you can read a timestamp value with the following code: