# Error Message:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
### The error may exist in com/dao/BookMapper.xml
### The error may involve com.dao.BookMapper.queryAllBook
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
java.sql.SQLException: Access denied for user 'Charles'@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Cause analysis:
-
- check the database.properties file, but there is no error </ OL>
driver = com.mysql.cj.jdbc.Driver
url = jdbc:mysql://localhost:3306/ssm?serverTimezone=UTC
username = root
password = admin
-
-
- the database used is mysql8.0, and the versions of database driver and database connection pool also match the database version </ OL>
-
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<!-- Database connection -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
-
-
-
- related dependencies are also added to the artifacts in project structure
-
-
-
-
-
- . There is no mistake in the spring Dao configuration file. All reference paths are correct </ OL>
-
-
<context:property-placeholder location="classpath:database.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"/>
<property name="jdbcUrl" value="${url}"/>
<property name="user" value="${username}"/>
<property name="password" value="${password}"/>
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<property name="autoCommitOnClose" value="false"/>
<property name="checkoutTimeout" value="10000"/>
<property name="acquireRetryAttempts" value="2"/>
</bean>
There is also a prompt when the cursor is placed on the value
online solutions have been tried and have not taken effect
Solution:
Finally, I accidentally tried to explicitly assign the attribute of the database connection pool, and the connection was successful
Read More:
- How to Solve Spring integrate Seata startup error
- Spring MVC uses Ajax to submit requests asynchronously to complete login
- [Solved] Spring Boot Error: org.springframework.jdbc.datasource.embedded.EmbeddedData
- Extracting JDBC tool class: JDBC utils
- How to Solve Spring Boot Maven Build Error
- [Solved] IDEA Error: Unknown system variable ‘tx_isolation‘ at
- [Solved] com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure error
- [Solved] Cannot find class: com.mysql.jdbc.Driver
- How to Solve c3p0 error (Cause & Solution)
- Solve the use of declaration transactions in spring java.lang.NoClassDefFoundError: org/aspectj/util/PartialOrder$PartialComparable
- How to Solve Error: No suitable driver found for
- How to Solve SQL comments error in the mybatis query
- How to Solve Error executing DDL in JPA
- How to Solve zipkin Install Error in Windows
- How to Solve Log4j 2.5 upgrade to 2.15 error
- How to Solve classnotfoundexception error in spark without Hadoop runtime
- How to Solve Swagger error: IllegalStateException
- How to Solve EasyExcel3.0.5 Version Error
- How to Solve Mybatisplusinterceptor error