InvalidConnectionAttributeException: The server time zone…

com.mysql.cj.core.exceptions.InvalidConnectionAttributeException:

The server time zone…

ICO容器连接MySQL数据库发生异常:

Exception in thread “main” org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (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.)

at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)

at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:382)

at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:456)

at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:464)

at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:472)

at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:477)

at org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:488)

at com.andy.smart.Main.main(Main.java:26)

Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (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.)

at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)

at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)

at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)

at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)

at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)

… 7 more

Caused by: 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.

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:569)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:537)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:527)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:512)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:480)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:498)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:494)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:69)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1634)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:637)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:351)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:224)

at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)

at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)

at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)

at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)

… 11 more

Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: 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.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)

at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73)

at com.mysql.cj.jdbc.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:118)

at com.mysql.cj.mysqla.MysqlaSession.configureTimezone(MysqlaSession.java:293)

at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:2424)

at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1767)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1624)

… 18 more

为了使MySQL JDBC驱动程序与UTC时区配合使用,在配置数据源URL时必须明确指定server Time Zone 时区:

url=”jdbc:mysql://localhost:3306/springtest?useUnicode=true&amp;useJDBCCompliantTimezoneShift=true&amp;

useLegacyDatetimeCode=false&amp;serverTimezone=UTC”

如果数据源不是在xml文件中配置,则不需要使用&的转义字符&amp;

0 Comments
Leave a Reply