mysql和mysql-connector-java版本匹配问题

下载了mysql5.8版本,使用5.1.21版本的mysql-connector-java连接时报错:

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 java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long ### 
The error may exist in com/example/springboot/mapper/StudentMapper.java (best guess) ### The error may involve com.example.springboot.mapper.StudentMapper.findAll ### 
The error occurred while executing a query ### 
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: 
java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long

实体类和DB中的字段映射没有问题。是因为低版本的mysql-connector-java和高版本的mysql不匹配造成,升级mysql-connector-java版本,如下:

<!-- mysql -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.46</version>
</dependency>

问题解决。

点赞