0

I have java.sql.Date and java.sql.timestamp objects in my Java code. I would like to insert them into a SQL Server column. Can this column's datatype be datetime?

From this https://learn.microsoft.com/en-us/sql/language-extensions/how-to/java-to-sql-data-types?view=sql-server-ver15 there are difference between java.sql.Date and timestamp, but I believe both would convert to datetime. Please correct me if I am wrong.

2
  • 1
    Why don't you just try it? Commented Mar 19, 2021 at 19:02
  • The documentation would answer this question. Commented Mar 19, 2021 at 21:05

1 Answer 1

1
  • Use java.sql.Date when you have to deal with only the date part (i.e. year, month and day).
  • Use java.sql.Timestamp when you have to deal with both, date and time.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.