数据库无法连接JDBC

Posted 云端观云

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库无法连接JDBC相关的知识,希望对你有一定的参考价值。

og4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.JobPersistenceException: Failed to obtain DB connection from data source ‘myDS‘: java.sql.SQLException: Connections could not be acquired from the underlying database! [See nested exception: java.sql.SQLException: Connections could not be acquired from the underlying database!]]
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.schedulerStarted(JobStoreSupport.java:693)
 at org.quartz.core.QuartzScheduler.start(QuartzScheduler.java:580)
 at org.quartz.impl.StdScheduler.start(StdScheduler.java:142)
 at org.quartz.ee.servlet.QuartzInitializerListener.contextInitialized(QuartzInitializerListener.java:198)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
 at org.apache.catalina.core.StandardService.start(StandardService.java:516)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.quartz.JobPersistenceException: Failed to obtain DB connection from data source ‘myDS‘: java.sql.SQLException: Connections could not be acquired from the underlying database! [See nested exception: java.sql.SQLException: Connections could not be acquired from the underlying database!]
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.getConnection(JobStoreSupport.java:777)
 at org.quartz.impl.jdbcjobstore.JobStoreTX.getNonManagedTXConnection(JobStoreTX.java:71)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3774)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3739)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.recoverJobs(JobStoreSupport.java:833)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.schedulerStarted(JobStoreSupport.java:691)
 ... 18 more
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
 at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
 at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
 at org.quartz.utils.PoolingConnectionProvider.getConnection(PoolingConnectionProvider.java:247)
 at org.quartz.utils.DBConnectionManager.getConnection(DBConnectionManager.java:108)
 at org.quartz.impl.jdbcjobstore.JobStoreSupport.getConnection(JobStoreSupport.java:774)
 ... 23 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could notacquire a resource from its primary factory or source.
 at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
 at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
 at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
 ... 27 more

 

 

以上问题可能有一下原因造成:

1,驱动配置有误:driver=com.mysql.jdbc.Driver
2,数据库连接地址有误:url=jdbc:mysql://localhost:3306/test?3useUnicode=true&characterEncoding=utf8
3,密码或帐号有误:username=root
      password=root

4,数据库未启动或无权访问

5,项目未引入对应的驱动jar包mysql-connector-java-5.1.6-bin.jar

6,mysql root没有远程访问的权限,需要增加权限,增加权限的步骤如下:
进入mysql数据库:
grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘root‘ with grant option;
flush privileges;

 

如果你也遇到过以上问题,但原因不是上面5种,请分享下解决方法,谢谢

















































以上是关于数据库无法连接JDBC的主要内容,如果未能解决你的问题,请参考以下文章

连接数据库时出错:无法为连接 URL 'null' 创建类 '' 的 JDBC 驱动程序

无法载入com.mysql.jdbc.Driver驱动程序! 无法连接数据库!

SpringBoot:GenericJDBCException:无法获取 JDBC 连接

大神们 无法获取JDBC连接,嵌套异常java.sql.SQLException:连接无法从基础数据库中获得! 怎么具体解决??

无法载入com.mysql.jdbc.Driver驱动程序! 无法连接数据库!

无法针对 JDBC 连接提交