一: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 is
com.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+时区设置