java.lang.Exception: java.sql.SQLException: Connections could not be acquired from the underlying database!
at cn.csg.yn.ydtf.pms.jlwlt.ypgjjc.YPGJJCSQL.getDYD(YPGJJCSQL.java:169)
at cn.csg.yn.ydtf.pms.jlwlt.ypgjjc.YPGJJCServlet.doPost(YPGJJCServlet.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:724)
以上问题可能有一下原因造成:
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;
/////////////////////////
Connections could not be acquired from the underlying database
"Connections could not be acquired from the underlying database" 大概意思是说:不能连接当前所配置的数据库.
出现这种问题,一般是配置参数有误.若连接mysql数据库的话,这时还要考虑你设置远程mysql.否则,也会出这个问题.
远程访问MySQL的设置
1.在User表中添加允许远程访问的用户
insert into mysql.user(Host,User,Password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,
Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,
References_priv,Index_priv,Alter_priv)
values ('url', 'username', 'password', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y','Y', 'Y');
然后重启mysql.
注意: 如果没有指定的固定IP地址,对应的Host设为空即可实现在任意机器上登录访问。
2.使用Grant分配权限
grant all on *.* to 'username' @'url' identified by 'password';
然后重启mysql.当前只是对指定ip进行权限分配的.还可以允许任何机器访问的.
注: 该命令与第一种方法得到的效果一模一样。username和password是连接当前数据库的用户名和密码.例如:grant all on *.* to 'root' @'192.168.0.55' identified by '123456';这意思是说允许连接数据库用户名为root,密码是123456的ip为192.168.0.55进行远程访问该数据库的增删改查操作.