Java 服务器时区值';AEST&x27;无法识别或表示多个时区

Java 服务器时区值';AEST&x27;无法识别或表示多个时区,java,mysql,hibernate,maven,Java,Mysql,Hibernate,Maven,我正在尝试设置一个简单的hibernate应用程序,当我运行它时,我会得到一个充满错误的堆栈跟踪 我的pom.xml文件中有以下maven依赖项: <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.0.Final</versi

我正在尝试设置一个简单的hibernate应用程序,当我运行它时,我会得到一个充满错误的堆栈跟踪

我的
pom.xml
文件中有以下maven依赖项:

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.0.Final</version>
    </dependency>
    <!-- http://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.2</version>
    </dependency>
我正在运行一个非常简单的方法,但仍然会出现错误:

// create session factory
SessionFactory factory = new Configuration()
            .configure("hibernate.cfg.xml")
            .addAnnotatedClass(Model.class)
            .buildSessionFactory();

// create session
Session session = factory.getCurrentSession();

Model newModel = new Model("....", "...", "...");

// start a transaction
session.beginTransaction();

// save the student object
System.out.println("Saving the model...");
session.save(newModel);
执行上述操作后,我得到一个很长的堆栈跟踪…System.out.println也不打印…因此连接似乎没有连接

INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Thu Jun 09 17:36:28 EST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:723)
    at com.parkingapi.tests.Test.main(Test.java:17)
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:105)
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123)
    at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:106)
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:40)
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:19)
    at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:138)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:110)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:74)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
    ... 14 more
Caused by: java.sql.SQLException: The server time zone value 'AEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:695)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:663)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:653)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:638)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:606)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:624)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:620)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:68)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1683)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:656)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:349)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)
    at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
    ... 29 more
Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value 'AEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)
    at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73)
    at com.mysql.cj.jdbc.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:118)
    at com.mysql.cj.mysqla.MysqlaSession.configureTimezone(MysqlaSession.java:308)
    at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:2474)
    at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1817)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1673)
    ... 33 more

原来
6.x
不兼容,移动到
5.1.39
修复了它。

尝试添加这些参数

jdbc:mysql://localhost:3306/fussa?useLegacyDatetimeCode=false&serverTimezone=UTC

我使用的是mysql连接器java 6.0.4

引发异常,因为mysql服务器时区(从系统时区继承)的格式与mysql连接器所期望的格式不同。您需要将MySql时区设置为“澳大利亚/悉尼”。请看这个令人敬畏的回复,了解详细信息:

  • 使用时区信息填充mysql架构:
mysql\u tzinfo\u to\u sql/usr/share/zoneinfo | mysql-u root-p mysql

  • 从mysql运行:
设置全球时区='澳大利亚/悉尼'

  • 重新启动mysql服务器
使用
&而不是
&

您也可以尝试更改mysql上的时区:

SET GLOBAL time_zone = '00:00'; 
并查看当前设置:

SELECT @@global.time_zone, @@session.time_zone;
build.gradle>

compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
application.properties>

spring.datasource.url=jdbc:mysql://localhost:3306/bookworm?useLegacyDatetimeCode=false&serverTimezone=UTC
-


这种组合对我很有效。

使用默认值

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/web_student_tracker?user=root&password=&useLegacyDatetimeCode=false&serverTimezone=UTC");

您好,您需要在URL说明符中指定,如下所示

 @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/jpahibernate?useLegacyDatetimeCode=false&serverTimezone=UTC");
        dataSource.setUsername("root");
        dataSource.setPassword("Password");
        return dataSource;
    }

在上面的代码片段中,查看一下
setUrl
property

这就是MySQLWorkbench版本的问题。升级至最新版本8.0,然后在jdbc URL中添加serverTimezone=UTC


String url=“jdbc:mysql://localhost:3306/your_db?useSSL=false&serverTimezone=UTC";

对于AEDT,正确的解决方案IMHO是按如下方式更改URL

jdbc:mysql://localhost:3306/sampledb?serverTimezone=Australia/Sydney

我有一个类似的问题,我使用的是mysql连接器java 8.0.15(最新版本),但出于某种原因,它仍然给我一个时区错误,我将它改为mysql连接器java 8.0.13,就这样做了。希望这是有用的。

如果使用Spring Boot,请尝试在localhost参数后添加一个问号,如下所示:

?serverTimezone=UTC&useLegacyDatetimeCode=false
例如,我有一个名为springboottutorial的mysql数据库。在本例中,参数如下所示:


spring.datasource.url=jdbc:mysql://localhost:3306/springboottutorial?serverTimezone=UTC&useLegacyDatetimeCode=false

在MySQL中:您可以使用以下命令:

  • 第一个解决方案:服务器时区=UTC添加到连接url

    spring.datasource.url=jdbc:mysql://localhost:3306/mydb?useSSL=false&serverTimezone=UTC
    
  • 第二种解决方案:nMySQLmy.ini文件集默认时区值如下所示

    # Set default time zone
    default-time-zone = '+08:00'
    

  • 我通过在数据库名称后面添加
    “?serverTimezone=America/Los_Angeles”
    解决了这个问题。我来自西海岸,我的地区名称是“美国/洛杉矶”
    。如果您不确定您的时区名称,请在RHEL/UBUNTU/CENTOS上运行下面的命令

    11:42 AM  ✔ user1 sfo-server1 Δ [~] Ω  timedatectl | grep "Time zone"
           Time zone: America/Los_Angeles (PDT, -0700)
    
    解决方案:

    jdbc_connection_string => "jdbc:mysql://localhost:3306/movielens**?serverTimezone=America/Los_Angeles**"
    

    加载时区数据后

    SET GLOBAL time_zone = 'Australia/Sydney';
    
    为我工作

    在我的例子中,我希望设置是持久性的,而这些都不适用于我持久化时区,最后我选择了设置启动参数,如下所示

    --default-time-zone=Australia/Sydney
    
    最常见的选择是在my.cnf中设置,但这对我也不起作用


    注意:我的是CentOS 8&MySql 8

    它是否与其他连接器(如C或ODBC)一起工作?没有尝试过吗?我该如何测试这一点@Michael OJDBC似乎是最流行的?例如,在PHP或Windows ODBC或unixODBC中。客户端和服务器上的属性
    user.timezone
    timezone.getDefault()
    )表示什么?您需要一个“实时”时区。CEST(中欧标准时间)也是如此——在这里,你必须决定欧洲/柏林或欧洲/巴黎等。对于AEST来说,这似乎是澳大利亚/悉尼、澳大利亚/塔斯马尼亚或澳大利亚/维多利亚。这对我来说很有效。我更新了我的Spring application.properties文件。我想将其设置为我的本地时区(山区时间),并希望它足够智能,能够处理夏令时(即MDT变为MST,全年再次返回)。此参数也可以添加到phpStorm数据库管理器中以进行连接。我将Linux服务器的/etc/localtime从/usr/share/zoneinfo/US/Pacific更新为/usr/share/zoneinfo/America/Los_Angeles,然后重新启动mysql服务,这为我解决了问题。我也遇到了同样的问题,这篇帖子解决了这个问题。无论如何,如果我在调试模式下启动应用程序,我会遇到以下异常:“线程中的异常”main“com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链路故障成功发送到服务器的最后一个数据包是0毫秒前的。驱动程序没有从服务器收到任何数据包”。有什么想法吗?为我工作!!!升级到8.0.11也解决了这一问题。连接器8.0.15似乎已损坏,需要上述修复。默认情况下,8.0.23使用本地时区,因此默认情况下不存在此问题,也适用于我,在使用mysql 8.0的SpringBoot上,这是不正确的;该URL未嵌入HTML页面,因此不应进行HTML转义。我需要与您联系,先生,在CentOS需要一些帮助。你可以在推特@ankitmishara上给我发DM吗?或者你可以给我一些我可以和你交谈的东西。
    11:42 AM  ✔ user1 sfo-server1 Δ [~] Ω  timedatectl | grep "Time zone"
           Time zone: America/Los_Angeles (PDT, -0700)
    
    jdbc_connection_string => "jdbc:mysql://localhost:3306/movielens**?serverTimezone=America/Los_Angeles**"
    
    SET GLOBAL time_zone = 'Australia/Sydney';
    
    --default-time-zone=Australia/Sydney