更新时间:2023-01-22 16:53:01
提供您使用的是JDBC 4.2或更高版本(我相信我们大多数人都在使用):
Provided that you are using JDBC 4.2 or higher (which I believe that most of us are):
myInsertStatement.setObject(1, currentTimeStamp)
但是,
LocalDateTime
对于时间戳来说是一个糟糕的选择,因为它不知道"其时区,因此作为时间点是模棱两可的.尽管我不了解SQL Server,但对于大多数数据库引擎而言,***将时间戳记与时区一起使用在数据库方面,而OffsetDateTime
在Scala方面.
LocalDateTime
is a poor choice for a timestamp, though, because it doesn’t "know" its time zone and therefore is ambiguous as a point in time. While I don’t know SQL Server, for most database engines it would be better to use timestamp with timezone on the database side and OffsetDateTime
on the Scala side.