报错描述
使用idea创建ssm测试项目,报错java.math.BigInteger cannot be cast to java.lang.Long,类型转换问题,但是可以保证数据库类型没有问题,代码也没有问题,就是报错,整了一天没整出来
报错信息:
org.apache.ibatis.exceptions.PersistenceException: Errorqueryingdatabase. Cause: java.sql.SQLException: java.lang.ClassCastException: java.math.BigIntegercannotbecasttojava.lang.LongTheerrormayexistincom/test/mapper/StudentMapper.xmlTheerrormayinvolvecom.test.mapper.StudentMapper.selectStudentTheerroroccurredwhileexecutingaqueryCause: java.sql.SQLException: java.lang.ClassCastException: java.math.BigIntegercannotbecasttojava.lang.Long
atorg.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136) atcom.test.app.Test.main(Test.java:31)
Causedby: java.sql.SQLException: java.lang.ClassCastException: java.math.BigIntegercannotbecasttojava.lang.Longatcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:988) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:974) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:919) atcom.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1041) atcom.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3496) atcom.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2460) atcom.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2230) atcom.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:813) atcom.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47) atsun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod) atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) atjava.lang.reflect.Constructor.newInstance(Constructor.java:423) atcom.mysql.jdbc.Util.handleNewInstance(Util.java:411) atcom.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399) atcom.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334) atjava.sql.DriverManager.getConnection(DriverManager.java:664) atjava.sql.DriverManager.getConnection(DriverManager.java:208) atorg.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201) atorg.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196) atorg.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93) atorg.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:385) atorg.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89) atorg.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138) atorg.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60) atorg.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336) atorg.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84) atorg.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) atorg.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) atorg.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) atorg.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) atorg.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) …3moreCausedby: java.lang.ClassCastException: java.math.BigIntegercannotbecasttojava.lang.Longatcom.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:992) …32more
解决方法
更改mysql驱动包版本,改后要在mysql的url后添加?useSSL=false
。已验证5.1.44以上可用