mysql-connector-java 6.x 使用(mysql 6.x驱动使用)

原创
2016/10/08 13:03
阅读数 3.2K

首先更新mysql-connector-java 的 jar 包,目前6.x 的最新版本是6.0.4:
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>6.0.4</version>
</dependency>

然后启动项目,发现出现异常:

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.
[WARNING] Unable to create initial connections of pool.
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)

看这句话:

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

是说mysql 的驱动类,位置改变了,修改配置文件:

把  driver_class=com.mysql.jdbc.Driver   修改为:   driver_class=com.mysql.cj.jdbc.Driver

再看下面这句话:

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.

说在配置文件中没有配置时区,然后mysql 不知道采用何种时区:

我们修改配置:

 jdbc_url=jdbc:mysql://127.0.0.1:3306/rx_shi?useUnicode=true&characterEncoding=utf8&useSSL=false

修改为

jdbc_url=jdbc:mysql:///rx_shi?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false

然后重新启动项目,成功没有保存,增删改查验证通过。

下面贴出来我的 5.1.39的老配置和新的配置:

 

 

 

 

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部