在将Java Date写入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?

查看:149
本文介绍了在将Java Date写入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 /6/docs/api/java/sql/PreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)\"rel =noreferrer> 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 Date写入SQL TIMESTAMP列之前,JDBC是否将日期从JVM时区转换为数据库会话时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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