1. 程式人生 > 實用技巧 >Connections could not be acquired from the underlying database!

Connections could not be acquired from the underlying database!

Connections could not be acquired from the underlying database!

報錯截圖:

報錯內容:

Exception in thread "main" java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
at com.courage.pool.c3p0.C3P0Test.main(C3P0Test.java:38)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1469)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)

報錯原因:

參考連結:MySQL JDBC Driver 5.1.33 - Time Zone Issue

MySQL JDBC驅動程式的5.1.33後面的版與UTC時區一起使用,必須serverTimezone在連線字串中顯式指定。

解決辦法:

在url後面加上時區資訊:

jdbc:mysql://localhost:3306/jdbc?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC