1. 程式人生 > >解決:Connections could not be acquired from the underlying database!

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

問題現場如下;

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

Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could notacquire 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