Mybatis框架的一些bug:Error querying database. Cause: java.sql.SQLException。driver class is ` `com.mysql.

一:mybatis配置xml 数据库的时间设置

报错:

Error querying database. Cause: java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone.

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: 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.
### The error may exist in com/itheima/dao/IUserDao.java (best guess)
### The error may involve com.itheima.dao.IUserDao.findAll
### The error occurred while executing a query
### Cause: 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.

解决:数据库配置的时间未设置,在mybatis配置文件的数据库配置项的后面添加大陆时间:?serverTimezone=GMT%2B8

property name=“url” value=“jdbc:mysql://localhost:3306/mybatis”

二 :5.x的mysql数据库与8.x的数据库的设置

报错:

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’.
The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

解决:5.x版本的驱动文件jar包对应的是:

 <!--配置数据库的4个基本信息-->
<property name="driver" value="com.mysql.jdbc.Driver"/>
Class.forName("com.mysql.jdbc.Driver");`
语句来加载数据库驱动
而我使用的是8.0x版本的数据库驱动文件,
对此,需要将加载数据库驱动的语句更改为:
Class.forName("com.mysql.cj.jdbc.Driver");

并且:在5.x和8.x 的url也会有区别:8.0x是不需要建立ssl连接的,你需要显示关闭,即url中的&useSSL=false;
url的设置也得进行修改,原本的url如下:

5.x String ur="jdbc:mysql://127.0.0.1:3306/student";

应修改为如下:String url="jdbc:mysql://127.0.0.1:3306/student?useUnicode=true&characterEncoding=UTF-8&userSSL=false&serverTimezone=GMT%2B8";

url基本格式:连接地址+ssl连接关闭+字符集为utf-8+时区设置

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值