Before writing a Java Date to an SQL TIMESTAMP column, does JDBC translate the date from the JVM time zone to the database session time zone?(在将 Java 日期写入 SQL TIMESTAMP 列之前,JDBC 是否会将日期从 JVM 时区转换为数据库会话时区?)
问题描述
在编写 Java 日期之前SQL TIMESTAMP 列,JDBC 将 Java 虚拟机时区的日期转换为数据库会话的日期?
Before writing a Java Date to an SQL TIMESTAMP column, does JDBC translate the date from the Java virtual machine time zone to that of the database session?
例如,假设 Java 虚拟机时区是 UTC 并且数据库会话时区是 UTC-5.如果 Java 程序尝试通过将 2000-01-01 00:00:00
传递给 PreparedStatement#setTimestamp(int, Timestamp)
,根据JDBC标准,数据库会存储TIMESTAMP '2000-01-01 00:00:00'
还是TIMESTAMP '1999-12-31 19:00:00'
?
For example, suppose the Java virtual machine time zone is UTC and the database session time zone is UTC-5. If a Java program attempts to store 2000-01-01 00:00:00
by passing it to PreparedStatement#setTimestamp(int, Timestamp)
, according to the JDBC standard, will the database store TIMESTAMP '2000-01-01 00:00:00'
or TIMESTAMP '1999-12-31 19:00:00'
?
推荐答案
不,JDBC 只是一个关于如何使用的 API客户端可以访问数据库.对于时间戳存储,这必须取决于编写符合 JDBC API 标准的数据库驱动程序的组织.
No, JDBC is just an API on how the client can access the database. For timestamp storage, this will have to be dependent by the organisation that writes their database drivers that conforms to the JDBC API standard.
这里一个MySQL实现PreparedStatement
的实现.他们似乎将 Java 的 JVM 时区带到了 MySQL 时区(检查 setTimestampInternal()
方法).
Here's an implementation of MySQL's implementation of PreparedStatement
. They seem to take Java's JVM timezone to MySQL Timezone (check the setTimestampInternal()
method).
这篇关于在将 Java 日期写入 SQL TIMESTAMP 列之前,JDBC 是否会将日期从 JVM 时区转换为数据库会话时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在将 Java 日期写入 SQL TIMESTAMP 列之前,JDBC 是否会将日期从 JVM 时区转换为数据库会话时区?


- C++ 和 Java 进程之间的共享内存 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01