The server time zone value 'Ö…
2018-09-29 04:02:20来源:博客园 阅读 ()
异常错误:The server time zone value '?D1ú±ê×?ê±??' 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.
1 Thu Sep 27 00:18:47 CST 2018 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. 2 java.sql.SQLException: The server time zone value '?D1ú±ê×?ê±??' 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. 3 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) 4 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) 5 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) 6 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) 7 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) 8 at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76) 9 at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832) 10 at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) 11 at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) 12 at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207) 13 at java.sql.DriverManager.getConnection(DriverManager.java:664) 14 at java.sql.DriverManager.getConnection(DriverManager.java:247) 15 at com.jdbc.chap02.sec03.Demo1.main(Demo1.java:33) 16 Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '?D1ú±ê×?ê±??' 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. 17 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 18 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 19 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 20 at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 21 at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) 22 at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85) 23 at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:128) 24 at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2236) 25 at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2260) 26 at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1314) 27 at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:963) 28 at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:822) 29 ... 6 more
我用了8.0版本的MySQL连接驱动。现在按照最新官方提示支持将com.mysql.jdbc.Driver 改为 com.mysql.cj.jdbc.Driver
1 //驱动名称 2 private static String jdbcName = "com.mysql.cj.jdbc.Driver"; 3 //数据库地址 4 private static String dbUrl = "jdbc:mysql://localhost:3306/db_book"; 5 //数据库用户名 6 private static String dbUser = "root"; 7 //数据库密码 8 private static String dbPassword = "123456";
我们还需要在访问数据库的Url后面加上以下的语句即可:
1 private static String dbUrl = "jdbc:mysql://localhost:3306/db_book?serverTimezone=GMT%2B8"
从错误上看应该是时区的错误,所以我们只需要设置完毕系统的时区即可。这里的GMT%2B8
代表东八区。
还有一种解决办法就是设置整个数据库的时区,可以执行下面的语句来完成:
1 show variables like '%time_zone%' 2 set global time_zone='+8:00'; 3 #执行结果: 4 Variable_name Value 5 system_time_zone 6 time_zone SYSTEM
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 【报错】导入项目后报错:Target runtime Apache Tomcat v7. 2020-05-25
- 第六章第三十三题(当前日期和时间)(Current date and time 2020-05-22
- Codewars Solution:Get the Middle Character 2020-05-21
- Java中Error和Exception的异同以及运行时异常(Runtime exce 2020-05-13
- 第六章第二十题(计算一个字符串中字母的个数)(Count the l 2020-05-09
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash