SSH框架--Hibernate配置

xiangqiao 2020-04-09

问题:

连接mysql数据库报错Connections could not be acquired from the underlying database!

解决流程:

1.检查Hibernate.cfg.xml配置文件中的驱动、URL、用户名和密码都没有问题

2.检查驱动,没问题

3.做sql连接测试,连接成功

import java.sql.DriverManager;

public class sqlTest {
    private static String url = "jdbc:mysql://localhost:端口号/数据库名";//数据库服务地址
    private static String driver = "com.mysql.jdbc.Driver";//驱动路径
    private static String username = "root";
    private static String password = "密码";
    
    public static void main(String[] args) throws Exception {
        Class.forName(driver).newInstance();

        //如果能连接成功,则打印连接
        System.out.println(DriverManager.getConnection(url, username, password));
        
    }
}

4.仔细查看报错:发现有这么一句

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

 资源池无法从其主工厂或源获取资源,测试连接数据库成功

说明有可能是资源池的问题,参考这位博主的做法,因此更换资源池jar包,失败。

5.https://blog.csdn.net/qinguanglong6606/article/details/100560901

大半夜的,挺累的[摊手],明天再站。

原因:

解决方案:

相关推荐