com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4e47db1f -- Acquisition Attempt Failed!!!

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4e47db1f – Acquisition Attempt Failed!!!—错误解决办法

我们的征程是星辰大海,而非人间烟尘

082403

错误详情图:

image

排除过程:

起初我以为是我的database.properties文件错了,我又写一个测试文件去链接数据库,但是结果就莫名其妙的可以,后来我觉得应该不是数据库的连接问题,又把错误放到,我的借口文件mapper.xml文件,我后面将这个接口注释掉发现可以跑起来,导致我一度觉得mapper.xml文件有问题,后来有重新写了一遍,mapper.xml文件,确信mapp
er.xml文件是没有问题的之后我就觉得是数据库的问题,我就写了两个测试方法:

import com.qifei.pojo.Books;
import com.qifei.service.BookService;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.*;

public class MyTest {
    @Test
    public void test(){
        ApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = classPathXmlApplicationContext.getBean("BookServiceImpl", BookService.class);
        for (Books books : bookServiceImpl.queryAllBook()) {
            System.out.println(books);
        }
    }

    @Test
    public void test2() throws SQLException {
        Connection connection = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8","root","111111");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //2) 得到语句对象
        Statement statement = connection.createStatement();
        //3) 执行 SQL 语句得到结果集 ResultSet 对象
        ResultSet rs = statement.executeQuery("select * from books");
        //4) 循环遍历取出每一条记录
        while(rs.next()) {
            int id = rs.getInt("bookID");
            String name = rs.getString("bookName");
            //5) 输出的控制台上
            System.out.println("编号:" + id + ", 书名:" + name );
        }
        //6) 释放资源
        rs.close();
        statement.close();
        connection.close();

    }
}

test()方法运行结果:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BGt5DdSf-1630313057814)(H:\博客截图\image-20210830163207140.png)]

test2()方法运行结果:

image

看到两个方法的结果,我确信我的database.properties里面的数据参数文件是没有错了。

然后看到test()结果里面说:

com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@270fcd06 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (2). Last acquisition attempt exception: 
java.sql.SQLException: Access denied for user 'Admin'@'localhost' (using password: YES)

再看看database.properties

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
username=root
password=111111

终于发现问题所在:

我明明是用root登陆,为什么会报Access denied for user 'Admin'@'localhost' (using password: YES) 这个错误,就算是要报错也是报Access denied for user 'root'@'localhost' (using password: YES) 不应该是Admin

百度得结果:

**最后把username改成jdbc.username就好了。**应该是username这个变量和系统的某个变量冲突了。

database.properties

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
jdbc.username=root
jdbc.password=111111

然后解决问题

附:

在maven中spring配置c3p0遇到的问题,其它地方遇到解决思路一致,如下:

1.检查四个参数是否有问题,注意大小写
2.检查数据库是否开启
3.检查是否导入了mysql-connector-jar包
4.检查mysql-connector-jar的jar包版本是否和数据库版本一致
列如我用的数据库的版本是8.0.12,那么对应的mysql-connector-ja的版本应该为8.x.x
用的数据库和jar包版本过高时,需要在URL后面加上
useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8

如果喜欢的欢迎点赞关注。谢谢 ~

本过高时,需要在URL后面加上
useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8

如果喜欢的欢迎点赞关注。谢谢 ~

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Liknana

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值