c3p0连接mysql8报错

        ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
        Properties properties = new Properties();
        properties.load(new FileInputStream("src\\mysql.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driver = properties.getProperty("driver");

        comboPooledDataSource.setDriverClass(driver);
        comboPooledDataSource.setJdbcUrl(url);
        comboPooledDataSource.setUser(user);
        comboPooledDataSource.setPassword(password);

        comboPooledDataSource.setInitialPoolSize(10);

        comboPooledDataSource.setMaxPoolSize(50);
        Connection connection = comboPooledDataSource.getConnection();
        connection.close();
        comboPooledDataSource.close();

有两个错误,密码用户都对的

  1. Public Key Retrieval is not allowed
  2. A ResourcePool could not acquire a resource from its primary factory or source.
    如果添加allowPublicKeyRetrieval=true参数,会用‘localhost’@‘localhost’不用我设置的密码

user=localhost
password=123456
url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&characterEncoding=utf8&useSSL=false&useUnicode=true
driver=com.mysql.cj.jdbc.Driver

参考文章:https://blog.csdn.net/ly2708169628/article/details/117791091
https://blog.csdn.net/naumy/article/details/107111722

给你找了一篇非常好的博客,你可以看看是否有帮助,链接:使用c3p0连接MySQL8