问题描述
在编写 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 时区转换为数据库会话时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)