hibernate和mysql的时区问题

a7qyws3x  于 2021-06-20  发布在  Mysql
关注(0)|答案(3)|浏览(414)

我正在尝试用tomcat(8.5)和mysql(v.8.0.12)配置hibernate(5.3.3 final)。当我启动hibernate.connection.url设置为'jdbc:mysql://localhost:3306/sakila'我遇到以下错误:

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当前设置在全局和会话的“系统”时区(mysql>选择@@global.time\u zone,@@session.time\u 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 post中提到的“mysql:”和“//localhost”之间的不可见字符“数据库url格式错误,无法解析主url节”。我试图通过mysql workbench设置本地时间(默认时区='+02:00')选项来解决这个问题,该选项适合马德里/巴黎的夏季时间(这里是我的例子)。它什么也改变不了。你知道吗?我必须在其他地方配置它吗?谢谢你的帮助,我已经在这上面三天了,没有成功。

yvt65v4c

yvt65v4c1#

以下url产生了错误: jdbc:mysql://localhost:3306/db?useLegacyDatetimeCode=false&serverTimezone=CET 这对我有效:替换 && .

n53p2ov0

n53p2ov02#

我终于找到了解决办法。因为看起来“&”也不能添加多个参数,我取出所有参数,只尝试了一个参数:

jdbc:mysql://localhost:3306/sakila?serverTimezone=UTC

它成功了,我再也没有问题了。

wgeznvg7

wgeznvg73#

你需要逃离 & :

jdbc:mysql://localhost:3306/sakila?useSSL=false&serverTimezone=UTC

更多信息请参见:https://docs.jboss.org/exojcr/1.12.13-ga/developer/en-us/html/ch-db-configuration-hibernate.html

相关问题