java.sql.SQLException: Unknown system variable 'tx_isolation’
在spring中使用c3p0连接池导致错误无法获取数据库连接。但在mybatis中获取连接是没有任何问题的。根据查阅资料发现
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4d236b0e – Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: Unknown system variable ‘tx_isolation’
根据查阅资料发现,mysql版本太低,驱动版本用的5.1.6,虽然不一样,但jdbc也可以连接。但使用Spring的c3p0连接池就会报错。
解决方法:
更新mysql驱动:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>`
修改连接数据库的driver和url:
<property name="driver" value="com.mysql.cj.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/mybatisdb?
useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT"></property>
重新运行