DBCP XAMPP不接受我的时区

时间:2017-12-19 20:55:50

标签: java mysql database timezone pool

当我尝试使用java中的DBCP连接到我的xampp mysql数据库时出现此错误:

Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value 'West-Europa (standaardtijd)' 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.

我尝试过很多东西,但我似乎无法修复它。这是我用来连接数据库的代码:

BasicDataSource ds = new BasicDataSource();
ds.setUsername("root");
ds.setPassword("");
ds.setUrl("jdbc:mysql://localhost/portfolio");

1 个答案:

答案 0 :(得分:0)

尝试在连接字符串中明确指定serverTimezone:

jdbc:mysql://localhost/portfolio?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC