版本
c3p0jar包版本:c3p0-0.9.1.2.jar
jdbc驱动包:mysql-connector-java-5.1.7-bin.jar
数据库mysql版本:8.0.12
问题1:
十二月 17, 2018 11:46:05 上午 com.mchange.v2.c3p0.DriverManagerDataSource ensureDriverLoaded
警告: Could not load driverClass com.mysql.cj.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)
at ...
十二月 17, 2018 11:46:05 上午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@36977f83 -- 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'
解决方法:jdbc驱动包:更新为mysql-connector-java-8.0.11.jar
上述问题解决,又出现了新的问题:
问题2:
WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
解决方法:在数据库配置url之后加上useSSL=false;
使用代码形式:
dataSource.setJdbcUrl("jdbc:mysql://localhost/bank?useSSL=false");
使用配置文件的形式:
url=jdbc:mysql://localhost:3306/bank?useSSL=false
上述问题解决,又出现了新的问题:
问题3:
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at sun.reflect.GeneratedConstructorAccessor6.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:83)
at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:128)
at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2201)
at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2225)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1391)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:993)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:852)
... 11 more
解决方法:在数据库url之后再加上serverTimezone=UTC
使用代码形式:
dataSource.setJdbcUrl("jdbc:mysql://localhost/bank?useSSL=false&serverTimezone=UTC");
使用配置文件:
url=jdbc:mysql://localhost:3306/bank?useSSL=false&serverTimezone=UTC
至此,全部解决。
总结
其实是数据库版本太高,而数据库驱动包版本太低导致的,更换更高版本的数据库驱动包即可,但是高版本的数据库强制SSL的使用,即使不使用,也需要显式的指出:useSSL=false
,而且需要指定时区:serverTimezone=UTC
。