简体   繁体   English

For java.sql.Date AND java.sql.timestamp, can both be converted to datetime in sql server?

[英]For java.sql.Date AND java.sql.timestamp, can both be converted to datetime in sql server?

I have java.sql.Date and java.sql.timestamp objects in my Java code. 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.我想将它们插入 SQL 服务器列。 Can this column's datatype be datetime ?此列的数据类型可以是datetime吗?

From this https://docs.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.从此https://docs.microsoft.com/en-us/sql/language-extensions/how-to/java-to-sql-data-types?view=sql-server-ver15 java.sql.Date存在差异java.sql.Datetimestamp ,但我相信两者都会转换为日期时间。 Please correct me if I am wrong.如果我错了,请纠正我。

  • Use java.sql.Date when you have to deal with only the date part (ie year, month and day).当您只需要处理日期部分(即年、月和日)时,请使用java.sql.Date
  • Use java.sql.Timestamp when you have to deal with both, date and time.当您必须同时处理日期和时间时,请使用java.sql.Timestamp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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