Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-990

Setting timezone=UTC result in SQLSyntaxErrorException

    XMLWordPrintable

Details

    Description

      Given a server that does not run in UTC, the new `timezone` parameter described here https://mariadb.com/kb/en/about-mariadb-connector-j/#jdbc-api-implementation-notes cannot work, even with mysql_tzinfo_to_sql fully and correctly loaded.

      In `StandardClient` UTC get's translated into a fixed offset:

      if (mustSetTimezone) {
              if (clientZoneId.getRules().isFixedOffset()) {
                ZoneOffset zoneOffset = clientZoneId.getRules().getOffset(Instant.now());
                sessionCommands.add("time_zone='" + zoneOffset.getId() + "'");
              } else {
                sessionCommands.add("time_zone='" + conf.timezone() + "'");
              }
            }
      

      Which is literal `Z` (See `System.out.println(ZoneId.of("UTC").getRules().getOffset(Instant.now()));`}

      MariaDB server cannot handle this, resulting in

      Exception in thread "main" java.sql.SQLSyntaxErrorException: (conn=2235) Setting configured timezone 'UTC' fail on server.
      Look at https://mariadb.com/kb/en/mysql_tzinfo_to_sql/ to load tz data on server, or set timezone=disable to disable setting client timezone.
      	at org.mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:280)
      	at org.mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:334)
      	at org.mariadb.jdbc.client.impl.StandardClient.postConnectionQueries(StandardClient.java:369)
      	at org.mariadb.jdbc.client.impl.StandardClient.<init>(StandardClient.java:205)
      	at org.mariadb.jdbc.Driver.connect(Driver.java:70)
      	at org.mariadb.jdbc.Driver.connect(Driver.java:101)
      	at org.mariadb.jdbc.Driver.connect(Driver.java:27)
      	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
      	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:229)
      

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            rotnroll666 Michael Simons
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.