作者:路过然后错过 | 来源:互联网 | 2022-12-08 17:09
我正在尝试使用tomcat(8.5)和mysql(v.8.0.12)配置hibernate(5.3.3 Final)。当我将hibernate.connection.url设置为'jdbc:mysql:// localhost:3306 / sakila'启动HibernateTest.java(教程中的非常简单的代码,这里没有问题)时,遇到以下错误:
Caused by: java.sql.SQLException: The server time zone value 'Paris, Madrid
(heure d?été)' 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.
MySQL当前在全局和会话的“ SYSTEM”时区上设置(mysql>选择@@ global.time_zone,@@ session.time_zone)。我的系统时区确实是巴黎/马德里。在我的hibernate.cfg.xml文件中,当我编写连接url时:
jdbc:mysql://localhost:3306/sakila?useJDBCCompliantTimezOneShift=true;useLegacyDatetimeCode=false;serverTimezOne=UTC;
错误是:
com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near '=false;serverTimezOne=UTC;'.
这不是stackoverflox帖子“带有mysql服务器时区和jdbc连接的问题”中提到的问题,因为Eclipse拒绝了“&”,请参见hibernate.cfg.xml文件的屏幕截图:
对实体“ useLegacyDatetimeCode”的引用必须以定界符“;”结尾
正如在stackoverflow帖子“格式错误的数据库URL,无法解析主要URL部分”中提到的那样,它不是'mysql:'和'// localhost'之间的不可见字符。我尝试通过MySql Workbench设置适合马德里/巴黎夏令时的本地时间(default-time-zOne='+02:00')选项来解决此问题(这里是我的情况)。它不会改变任何事情。任何的想法?我是否需要在其他地方进行配置?谢谢您的帮助,我已经参加了这三天的活动,但没有成功。
1> 小智..:
您需要转义&
:
jdbc:mysql://localhost:3306/sakila?useSSL=false&serverTimezOne=UTC
在此处查看更多信息:https : //docs.jboss.org/exojcr/1.12.13-GA/developer/zh-CN/html/ch-db-configuration-hibernate.html