mysql-8.0.11 jdbc连接数据库 The server time zone value ‘�й���ʱ��’ is unrecognized or represents more… 错误
2018-05-12 18:13
811 查看
Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���ʱ��’ 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.
解决方法
根据异常提示可知需要添加对应的时区,修改url即可
阅读更多String url = String.format(“jdbc:mysql://%s:%d/%s?characterEncoding=%s&serverTimezone=UTC”, host, port, database, encoding);
在XML中
提示系统时区出现错误,可以在mysql中执行命令:
set global time_zone='+8:00'
或者在数据库驱动的url后加上serverTimezone=UTC参数写代码的时候要注意,如果该参数是‘?’后的第一个,即
<property name="jdbcUrl"> jdbc:mysql://localhost:3306/exam?serverTimezone=UTC </property>是没有问题的,但如果不是第一个,即<property name="jdbcUrl"> jdbc:mysql://localhost:3306/exam?characterEncoding=utf8&serverTimezone=UTC </property>这种写法是会报错的,会提示The reference to entity “serverTimezone” must end with the ‘;’ delimiter.
运行后控制台也会出现
对实体 “serverTimezone” 的引用必须以 ‘;’ 分隔符结尾。
的错误提示。
将代码改为<property name="jdbcUrl"> jdbc:mysql://localhost:3306/exam?characterEncoding=utf8&serverTimezone=UTC </property>即可。在xml的配置文件中 ;要用&代替。
相关文章推荐
- jdbc连接数据库 The server time zone value '�й���ʱ��' is unrecognized or represents more... 错误
- 连接数据库:ERROR: The server time zone value '�й�' is unrecognized or represents more than one time zone
- mysql出现错误:The server time zone value is unrecognized or represents more than one time zone
- 数据库连接 The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone.
- Mysql错误:The server time zone value is unrecognized or represents more than one time zone
- 连接MySQL时区bug: The server time zone value '�й���ʱ��' is unrecognized or represents more
- Mysql错误:The server time zone value is unrecognized or represents more than one time zone
- mysql连接异常:The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zo
- mysql运行报The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one 解決辦法
- 解决mysql java.sql.SQLException: The server time zone value‘XXXXXX' is unrecognized or represents...
- 解决mysql java.sql.SQLException: The server time zone value‘XXXXXX' is unrecognized or represents...
- The server timezone value 'xxx' is unrecognized or represents more than one time
- The server time zone value '?й???????' is unrecognized or represents more than one time zone. You mu
- The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You mu
- 巨坑:The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone.
- The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone.
- java.sql.SQLException: The server time zone value '�й���ʱ��' is unrecognized or represents more tha
- The server time zone value 'PDT' is unrecognized or represents more than one time zone
- 解决mysql java.sql.SQLException: The server time zone value‘XXXXXX' is unrecognized or represents...
- 【问题解决:时区】连接MySQL时错误The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone