Skip to content

[jdbc] Incorrect DateTime results when writing numeric data with use_time_zone property #2065

Closed

Description

@haishui126

Describe the bug

The DateTime results will -8h when inserting long values using PrepareStatement with use_server_time_zone=false&use_time_zone=Asia/Shanghai. (ClickHouse Server timezone is UTC)

Expected: '1970-01-01 08:00:00.001000000'
Actual: '1970-01-01 00:00:00.001000000'
(timezone is Asia/Shanghai)

Code example

CREATE TABLE t_test
(
    `timestamp` DateTime64(3)
)
ENGINE = Log;
try (
    Connection connection = DriverManager.getConnection("jdbc:ch://localhost:8123/default?use_server_time_zone=false&use_time_zone=Asia/Shanghai", "default", "");
    PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO t_test VALUES (?)")
) {
    preparedStatement.setLong(1, 1);
    preparedStatement.execute();
}

Configuration

Environment

  • Client version: 0.7.2
  • Language version: java11

Activity

  1. haishui126 commented on Jan 3, 2025

    @haishui126
    ContributorAuthor

    Hi team,
    I think the method in com.clickhouse.data.ClickHouseValues.java:282 is incorrect. Why should a numeric type representing a Unix timestamp, which inherently lacks timezone context, be directly converted to a LocalDateTime assuming it's in the UTC time zone?

    public static LocalDateTime convertToDateTime(BigDecimal value) {
        return value != null ? LocalDateTime.ofInstant(convertToInstant(value), ZoneOffset.UTC) : null;
    }

    The concern here is that the conversion assumes the input Unix timestamp is in UTC without verifying if this is correct for all cases, which can lead to time zone discrepancies when clients operate in different time zones.

  2. added this to the Priority Backlog milestone on May 8, 2025
  3. removed this from the Priority Backlog milestone on Jun 4, 2025
  4. self-assigned this
    on Jul 24, 2025
  5. added this to the 0.9.3 milestone on Aug 20, 2025
  6. chernser commented on Aug 28, 2025

    @chernser
    Contributor

    Good day, @haishui126 !
    Sorry for a delayed answer and thank you for reporting the issue!

    We will look into it but this is a v1.
    Would you please try v2 (set by default after 0.8.0)? Thanks!

  7. added and removed
    jdbc-v2jdbc-v2 issues
    on Aug 28, 2025
  8. dyjwi4-wiqvyr-cyZbem commented on Aug 28, 2025

    @dyjwi4-wiqvyr-cyZbem
  9. modified the milestones: 0.9.3, 0.9.4 on Oct 1, 2025
  10. modified the milestones: 0.9.5, 0.9.6 on Jan 6, 2026
  11. modified the milestones: 0.9.6, 0.9.7 on Jan 21, 2026
  12. chernser commented on Feb 26, 2026

    @chernser
    Contributor

    Good day, @haishui126 !

    use_server_time_zone has no effect on numbers. Driver doesn't know target column type and no type hint is provided.
    Besides driver is not to convert data.

    We have created a guide for how to work with Date Time https://clickhouse.com/docs/integrations/language-clients/java/jdbc_date_time_guide .

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions