现在的位置: 首页 > 综合 > 正文

解决:Connections could not be acquired from the underlying database!

2018年05月19日 ⁄ 综合 ⁄ 共 853字 ⁄ 字号 评论关闭

问题现场如下;

Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!

Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException:
A ResourcePool could not
acquire a resource from its primary factory or source.

可能解决该问题的办法有:

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;

7.在普通java项目中使用 mybatis+C3p0+spring时也遇见上述问题。
问题原因是:在xml配置文件中显示声明了自动装载  <beans default-autowire="byName"> 几经折腾,把自动装载设置去掉,就没有问题了,应该使用默认的 byType。

参考的文章http://jyao.iteye.com/blog/1915561

抱歉!评论已关闭.