项目启动报错:

  

 [2016-07-13 10:04:15,074] ERROR org.apache.ibatis.executor.BaseExecutor Could not get a databaseId from dataSource
java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:264)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at com.mchange.v2.c3p0.ComboPooledDataSource.getConnection(ComboPooledDataSource.java:521)
at org.apache.ibatis.mapping.VendorDatabaseIdProvider.getDatabaseProductName(VendorDatabaseIdProvider.java:77)
at org.apache.ibatis.mapping.VendorDatabaseIdProvider.getDatabaseName(VendorDatabaseIdProvider.java:62)
at org.apache.ibatis.mapping.VendorDatabaseIdProvider.getDatabaseId(VendorDatabaseIdProvider.java:50)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:445)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4210)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4709)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:802)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:583)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1080)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1003)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:507)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1322)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:325)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1068)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
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.awaitAcquire(BasicResourcePool.java:972)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:260)
... 45 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;

延伸:

1、在普通java项目中使用 mybatis+C3p0+spring时也遇见上述问题。

问题原因是:在xml配置文件中显示声明了自动装载  <beans default-autowire="byName">
解决方法:    把自动装载设置去掉,就没有问题了,应该使用默认的 byType

2、同一个ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值)中断的数据库连接而导致的阻塞,引发的。

解决方法:  重启数据库服务或者使用mysqladmin flush-hosts 命令清理一下hosts文件。

3、maven+spring 项目,用了org.apache.tomcat.jdbc.pool.DataSource;  报错:Could not get JDBC Connection; nested exception is java.sql.SQLException: com.mysql.jdbc.Driver

解决方法:  需要加入 tomcat-jdbc的引用

【JDBC 报错】Connections could not be acquired from the underlying database!的更多相关文章

  1. Connections could not be acquired from the underlying database!

    Connections could not be acquired from the underlying database! 报错截图: 报错内容: Exception in thread &quo ...

  2. JavaWeb:c3p0配置问题-----java.sql.SQLException: Connections could not be acquired from the underlying database!

    错误原因 c3p0的配置错误 错误显示 -classpath "D:\Program\Software\IntelliJIDEA\IntelliJ IDEA 2018.2.5\lib\ide ...

  3. 数据库连接问题之:Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!

    要么是驱动问题(没加载到工程中去或者其他问题)要么是账号密码或者url或者driver写错 driver:com.mysql.jdbc.Driver url:jdbc:mysql://localhos ...

  4. c3p0:Connections could not be acquired from the underlying database!解决方案

    在利用ssh框架做网站的时候遇到了一个比较棘手的问题,一直连接不上数据库,问题描述如下: 各种百度然后说的最多的解决方案是: 1,驱动配置有误:2,数据库连接地址有误:3,密码或帐号有误: 4,数据库 ...

  5. dea创建Maven工程用c3p0连接数据库报错java.sql.SQLException: Connections could not be acquired from the underlying

    idea   java.sql.SQLException: Connections could not be acquired from the underlying database! 转载自:ht ...

  6. java中JDBC报错(一)

    java中JDBC报错(一) 1.具体报错如下 com.mysql.jdbc.MySqlDataTruncation:Data truncation:Data too long for column ...

  7. java项目连接jdbc报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server

    java项目连接jdbc报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not creat ...

  8. JDBC报错:The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone

    报错原因:查阅资料发现这都是因为安装mysql的时候时区设置的不正确 mysql默认的是美国的时区,而我们中国大陆要比他们迟8小时,采用+8:00格式 解决方法: 1.修改MySQL的配置文件,MyS ...

  9. JDBC报错:Cannot find class: com.mysql.jdbc.Driver

    连接数据库的jar出现异常(通常报错:Cannot find class:com.mysql.jdbc.Drive), 问题:Connector的jar已经导入,还是出现 Cause: java.sq ...

随机推荐

  1. checksum table 【转】

    来自:http://dinglin.iteye.com/blog/1791922 有同学问到 checksum table在逻辑备份时候前后是否可以用于验证数据一致性.扩展一下发现有一些有趣的问题,比 ...

  2. yii框架详解 之 国际化 (I18N)

    我们要开启组件中们关于语言的配置,默认的就是CPhpMessageSource,也可以改为其他的方式. #组件配置中  'messages' => array(     'class'=> ...

  3. XP共享连接数限制

  4. bind+dlz+mysql实现区域记录动态更新

    BIND-DLZ实验:http://bind-dlz.sourceforge.net/ 实验环境:RHEL4,BIND-9.5.0-P2.tar.gz(9.4.0以上版本都已含DLZ补丁),Mysql ...

  5. HTML中表格元素TABLE,TR,TD及属性的语法

    table:表格元素及属性 <table width="80%" border="1" cellspacing="1" cellpad ...

  6. 穹举,迭代,while循环。

    所有循环  必要条件 :   初始条件(注意初始条件的位置)   循环条件   循环体   状态改变: 1.穷举 将所有可能性全部全部走一遍,使用IF筛选出满足的情况 使用循环语句    for   ...

  7. 如何把一个excel工作薄中N个工作表复制到另一个工作薄中

    一般遇到标题这样的情况,许多人可能会一个一个的复制粘贴,其实完全不必那么麻烦. 你可以按以下步骤来操作: 第一步:打开所有要操作的excel工作薄\n 第二步:按住Shift键,选择所有要复制的工作表 ...

  8. js控制表格单双行颜色交替显示

    <script language="JavaScript"> window.onload = function() { var Table=document.getEl ...

  9. ASP.net绑定文本框Enter事件到按钮 ASP.NET执行后台执行JS方法

    txtAccountBarcode.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if (( ...

  10. eclipse 注释模板

    位置:window -> Preferences -> java -> Code Style -> Code Templates <?xml version=" ...