小白学习MyBatis遇到的报错,都是小问题,记录一下供参考。
控制台报错如下:
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.
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\lyh\entity\UsersMapper.xml
### The error may involve test.findUserByName
### The error occurred while executing a query
### Cause: java.sql.SQLException: The server time zone value '�й���ʱ��'
错误代码:
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/bookstore"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
这里面我的connector.jar包版本是8.0.16
两个可以找出的明显错误分别是:
1.com.mysql.jdbc.Driver驱动弃用了,应是jar包版本比较高。
2.时区异常
解决方案:
1.按照提示更换新驱动
2.在数据库名后面添加时区设置
改正后代码:
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/bookstore?serverTimezone=UTC"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
改正后运行结果:
成功运行。