我们先来看看出现的异常信息,如下。
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 2,594 milliseconds ago. The last packet sent successfully to the server was 2,580 milliseconds ago.
### The error may exist in com/qijian/dao/UserMapper.xml
### The error may involve com.qijian.dao.UserDao.getUserList
### The error occurred while executing a query
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 2,594 milliseconds ago. The last packet sent successfully to the server was 2,580 milliseconds ago.
从错误信息中我们可以看到是查询数据库出现错误,以至于我一度以为是我的idea配置数据库出现错误,反复检查了几遍发现没有什么问题。后来百度了一下找到了一篇文章跟着改了一下发现问题的确解决了。如下
原:
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8"
改:
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
问题解决输出了结果:
User{id=1, name='qijian', pwd='123'}
User{id=2, name='Tom', pwd='123'}
User{id=3, name='lisi', pwd='123'}
但是还是不太明白:
MySQL5.7以及MySQL5.7以上的版本需要配置ssl证书,并且MySQL5.7默认是开启SSL连接,如果强制用户使用SSL连接,那么应用程序的配置也需要明确指定SSL相关参数,否则程序会报错。因为之前用的是MySQL5.7以下的版本所以完全忽略了 。
有关更多相关的问题参考: