Mysql与JDBC版本兼容性问题

一、报错信息

mybaits查询报错:

Tue Oct 20 15:46:34 CST 2020
There was an unexpected error (type=Internal Server Error, status=500).nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException:
Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
### The error may exist in file [D:\project\mybatis\target\classes\mapper\TruckInfoMapper.xml]
### The error may involve com.example.mybatis.cache.dao.mapper.TruckInfoMapper.getTruckInfo
### The error occurred
while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException:
Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

 

二、问题排查

  从报错信息上预测是JDBC连接获取失败导致。因此,首先查询mysql版本和jdbc版本。

1、查询mysql版本

 Mysql版本为8.0.19。

 

2、查询JDBC版本

 JDBC版本为5.1.39。

 

3、问题结论

  Mysql与JDBC版本不一致,兼容性问题导致JDBC连接获取失败。

 

三、解决方案

1、升级JDBC版本,5.1.39--->8.0.122、修改数据库驱动,  driver-class-name: com.mysql.cj.jdbc.Driver

 

 

posted @ 2020-10-20 16:33  马非白即黑  阅读(4162)  评论(0编辑  收藏  举报