Java JDBC Tutorial – Inserting Date and Time

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:

Did you like my blog post?

Signup now and receive an email when I publish new luv2code content.

I will never give away, trade or sell your email address. You can unsubscribe at any time.

Share

Leave a Reply