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

  1. 云栖社区>
  2. 博客>
  3. 正文

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

~信~仰~ 2018-10-11 11:37:37 浏览4420
展开阅读全文

下载了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>

问题解决。

网友评论

登录后评论
0/500
评论
~信~仰~
+ 关注