在将 Java 日期写入 SQL TIMESTAMP 列之前,JDBC 是否会将日期从 JVM 时区转换为数据库会话时区? [英] 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?

查看:17
本文介绍了在将 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 时区转换为数据库会话时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆