Java 服务器时区值“AEST”无法识别或代表多个时区
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37719818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The server time zone value 'AEST' is unrecognized or represents more than one time zone
提问by James111
I'm trying to setup a simple hibernate application, when I run it I get a stack trace full of errors.
我正在尝试设置一个简单的休眠应用程序,当我运行它时,我得到一个充满错误的堆栈跟踪。
I have the following maven dependencies in my pom.xml
file:
我的文件中有以下 Maven 依赖项pom.xml
:
<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>
And the mysql version I'm running locally is:
我在本地运行的 mysql 版本是:
5.7.9, for osx10.11 (x86_64)
I'm running, what seems, a very simple method, and still getting errors:
我正在运行,似乎是一个非常简单的方法,但仍然出现错误:
// 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);
After the above is executed, I get a long stack trace...The System.out.println doesn't print either...So the connection just doesn't seem to be connecting.
执行上述操作后,我得到了很长的堆栈跟踪…… 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.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
I'm focused on this error here:
我在这里专注于这个错误:
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.
服务器时区值“AEST”无法识别或代表多个时区。如果您想利用时区支持,您必须将服务器或 JDBC 驱动程序(通过 serverTimezone 配置属性)配置为使用更具体的时区值。
I'm unsure how I fix it?
我不确定我如何解决它?
Edit:
编辑:
Printing out the Timezone (System.out.println(TimeZone.getDefault());) prints the following details:
打印时区 (System.out.println(TimeZone.getDefault());) 打印以下详细信息:
sun.util.calendar.ZoneInfo[id="Australia/Melbourne",offset=36000000,dstSavings=3600000,useDaylight=true,transitions=142,lastRule=java.util.SimpleTimeZone[id=Australia/Melbourne,offset=36000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=9,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=1,endMode=3,endMonth=3,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=1]]
sun.util.calendar.ZoneInfo[id="澳大利亚/墨尔本",offset=36000000,dstSavings=3600000,useDaylight=true,transitions=142,lastRule=java.util.SimpleTimeZone[id=澳大利亚/墨尔本,offset=3600000,useDaylight=true,transitions=142,lastRule=java.util.SimpleTimeZone[id=澳大利亚/墨尔本,offset=3600000] dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=9,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=1,endMode=3,endMonth=3,endDay=1,endDayOfWeek= 1,endTime=7200000,endTimeMode=1]]
Edit:
编辑:
So I looked at the question which was flagged, and tried to change my connection string, but it's still throwing the same stack trace. Below is my new connection url. As you can see I changed the serverTimezone to that of the printed Timezone.getDefault()
所以我查看了被标记的问题,并尝试更改我的连接字符串,但它仍然抛出相同的堆栈跟踪。下面是我的新连接网址。如您所见,我将 serverTimezone 更改为打印的Timezone.getDefault()
jdbc:mysql://localhost:3306/parking_hib?useLegacyDatetimeCode=false;serverTimezone=Australia/Melbourne;useSSL=false;
采纳答案by James111
Turns out 6.x
wasn't compatible, moving to 5.1.39
fixed it.
原来6.x
是不兼容,移动5.1.39
修复它。
回答by FuSsA
try to add those parameters..
尝试添加这些参数..
jdbc:mysql://localhost:3306/fussa?useLegacyDatetimeCode=false&serverTimezone=UTC
i'm using mysql-connector-java 6.0.4
我正在使用mysql-connector-java 6.0.4
回答by gabi.m
The exception is thrown because the MySql server timezone (inherited from the system timezone) is in a different format than what the mysql connector expects. You need to set MySql timezone to be 'Australia/Sydney'. Look at this awesome response for details: Should MySQL have its timezone set to UTC?
抛出异常是因为 MySql 服务器时区(从系统时区继承)的格式与 mysql 连接器期望的格式不同。您需要将 MySql 时区设置为“澳大利亚/悉尼”。看看这个很棒的回复的详细信息:MySQL should have its timezone set to UTC?
- populate the mysql schema with the timezone information:
- 使用时区信息填充 mysql 架构:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
- from mysql run:
- 从 mysql 运行:
SET GLOBAL time_zone = 'Australia/Sydney';
SET GLOBAL time_zone = 'Australia/Sydney';
- restart mysql server
- 重启mysql服务器
回答by user2087635
jdbc:mysql://localhost:3306/fussa?useLegacyDatetimeCode=false&serverTimezone=UTC
Use &
instead of &
.
使用&
代替&
。
You can try change the timezone on mysql too:
您也可以尝试更改 mysql 上的时区:
SET GLOBAL time_zone = '00:00';
And see the current setting:
并查看当前设置:
SELECT @@global.time_zone, @@session.time_zone;
回答by catch22
build.gradle >
构建.gradle >
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
application.properties >
application.properties >
spring.datasource.url=jdbc:mysql://localhost:3306/bookworm?useLegacyDatetimeCode=false&serverTimezone=UTC
-
——
mysql --version
mysql Ver 8.0.11 for osx10.13 on x86_64 (Homebrew)
This combination works for me.
这种组合对我有用。
回答by antelove
Using default
使用默认
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/web_student_tracker?user=root&password=&useLegacyDatetimeCode=false&serverTimezone=UTC");
回答by Darshan
Hi You need to specify in you URL specifier like below
嗨,您需要在 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;
}
In the above code snippet have a look on setUrl
property
在上面的代码片段中查看setUrl
属性
回答by 2rahulsk
This is the problem of the version of the MySQLWorkbench. Upgrade to the latest version which is 8.0 and then add serverTimezone=UTC in your jdbc URL.
这是MySQLWorkbench版本的问题。升级到最新版本 8.0,然后在 jdbc URL 中添加 serverTimezone=UTC。
String url = "jdbc:mysql://localhost:3306/your_db?useSSL=false&serverTimezone=UTC";
String url = "jdbc:mysql://localhost:3306/your_db?useSSL=false&serverTimezone=UTC";
回答by Gunith D
The proper solution, IMHO for AEDT, is to change the URL as follows,
AEDT 恕我直言,正确的解决方案是更改 URL,如下所示,
jdbc:mysql://localhost:3306/sampledb?serverTimezone=Australia/Sydney
回答by NUKE
I had a similar issue, i was using mysql-connector-java 8.0.15 (latest), but for some reaon it was still giving me a timezone error, i changed it for mysql-connector-java 8.0.13 and that just did it. Hope thats be usefull.
我有一个类似的问题,我使用的是 mysql-connector-java 8.0.15(最新),但出于某种原因,它仍然给我一个时区错误,我将它更改为 mysql-connector-java 8.0.13 并且刚刚做到它。希望那是有用的。