使用C3P0连接MySQL 8.0.19数据库出现异常:Unknown system variable 'tx_isolation'

在做架构迁移的时候,使用C3P0连接MySQL 8.0.19数据库出现如下异常:

java.sql.SQLException: Unknown system variable 'tx_isolation'

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1094)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4208)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4140)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2597)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2758)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2820)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2769)

at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1569)

at com.mysql.jdbc.ConnectionImpl.getTransactionIsolation(ConnectionImpl.java:3372)

at com.mchange.v2.c3p0.impl.NewPooledConnection.(NewPooledConnection.java:70)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:98)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.acquireResource(C3P0PooledConnectionPool.java:83)

at com.mchange.v2.resourcepool.BasicResourcePool.assimilateResource(BasicResourcePool.java:884)

at com.mchange.v2.resourcepool.BasicResourcePool.acquireUntil(BasicResourcePool.java:601)

at com.mchange.v2.resourcepool.BasicResourcePool.access$400(BasicResourcePool.java:31)

at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1079)

at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:354)

原因:在低版本的MySQL中,tx_isolation是作为transaction_isolation(查询事务隔离级别)的别名被应用的,高版本已经弃用。

解决方法:升级mysql-connector-java.jar的版本。

 

你可能感兴趣的:(异常集锦,c3p0,mysql)