connector-j 8.0-为sqltimestampvaluefactory设置时区?

0kjbasz6  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(337)

我有10~mysql表和20~ DATETIME 领域。并尝试将表从mysql迁移到googlebigquery。
在这个过程中,我碰巧使用了mysql-connector-j8.0.x,据我所知,mysql DATETIME 不知道时区。和bigquery的 TIMESTAMP 将时间戳保存为utc。
所以我应该换衣服 DATETIME 有时区信息。
我想应该由我来处理 SqlTimestampValueFactory . 我的猜测正确吗?如果这是真的,我该如何定制 tzSqlTimestampValueFactory ?

flmtquvp

flmtquvp1#

您可以通过设置 serverTimezone 财产。
即使mysql DATETIME datetype没有时区信息。时区假设由服务器变量完成 time_zone . 以及 mysql-connector-j 处理转换通过 TimestampValueFactoryServerSession.getDefaultTimezone() .
所以就我而言 serverTimezone 属性设置就足够了。
热释光;博士
sqltimestampvaluefactory在ResultSeimpl处初始化。


# com.mysql.cj.jdbc.result.ResultSetImpl#ResultSetImpl

this.defaultTimestampValueFactory = 
   decorateDateTimeValueFactory(
      new SqlTimestampValueFactory(
          this.session.getServerSession().getDefaultTimeZone()),
          this.zeroDateTimeBehavior);

nativeprotocol正在初始化defaulttimezone

String canonicalTimezone = getPropertySet().getStringReadableProperty(PropertyDefinitions.PNAME_serverTimezone).getValue();
...
...
if (canonicalTimezone != null && canonicalTimezone.length() > 0) {
        this.serverSession.setServerTimeZone(TimeZone.getTimeZone(canonicalTimezone));
...

相关问题