c3p0連接池:com.mysql.cj.exceptions.InvalidConnectionAttributeException


1 遇到的錯誤com.mysql.cj.exceptions.InvalidConnectionAttributeException:

 1 四月 17, 2019 10:21:13 上午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
 2 信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 2udui8a2beimx6x8ptry|2f4d3709, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2udui8a2beimx6x8ptry|2f4d3709, idleConnectionTestPeriod -> 0, initialPoolSize -> 20, jdbcUrl -> jdbc:mysql://localhost:3306/test, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 30, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
 3 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
 4 四月 17, 2019 10:21:33 上午 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
 5 警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@26aa877c -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
 6 四月 17, 2019 10:21:33 上午 com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
 7 警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@26aa877c -- APPARENT DEADLOCK!!! Complete Status: 
 8     Managed Threads: 3
 9     Active Threads: 3
10     Active Tasks: 
11     ....    
12 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.
13     at sun.reflect.GeneratedConstructorAccessor32.newInstance(Unknown Source)
14     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
15     at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
16     at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
17     at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
18     at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
19     at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2234)
20     at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2258)
21     at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)
22     at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966)
23     at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
24     ... 11 more

 

2 解析

參考博客地址:https://blog.csdn.net/weixin_37577564/article/details/80329775

 

the server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. 

出現這個的原因是因為 mysql返回的時間總是有問題,比實際時間要早8小時。

jdbc連接的url后面加上serverTimezone=GMT即可解決問題,如果需要使用gmt+8時區,需要寫成GMT%2B8

 

3 解決方法

注意:首先檢查mysql-connector-java-xxx.jar的版本,若過低,升成8.0.13

 

3.1 如果是在Java工具類里:

 

dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false");

 

3.2 如果是在配置文件里:

<property name="jdbcUrl">jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf8&amp;serverTimezone=GMT%2B8&amp;useSSL=false</property>

 

以上,吼吼

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM