MySQL数据库连接时区问题


    
    
    
            
            
            
            
    

配置中的url这样写的话会报错_如下

严重: create connection SQLException, url: jdbc:mysql://localhost:3306/db01, errorCode 0, state 01S00
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:129)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
	at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1558)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2468)

主要原因翻译过来之后显示时区异常

服务器时区值 ' й ׼ɦ ' 无法识别或表示多个时区。如果要利用时区支持,则必须将服务器或 JDBC 驱动程序(通过 serverTimezone 配置属性)配置为使用更具体的时区值。

解决办法:

将xml中配置url的value改成如下:

即加上服务器时区

就好啦!(下面是输出结果)

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2月 16, 2022 12:41:24 下午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} inited
1

你可能感兴趣的:(SSM学习总结及分享,mysql,数据库,java,jdbc,spring,5)