一、報錯信息
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.12。 2、修改數據庫驅動, driver-class-name: com.mysql.cj.jdbc.Driver