關於使用C3P0程序報錯Having failed to acquire a resource, com.mchange.v2.resourcepool的問題


由於是新手的問題,C3P0的使用時嚴格跟着視頻來的,但是問題卻來的很突然

在導入了三個包以及創建了路徑以后

進行測試

class JdbcutilsTest {

    @Test
    void TestGetConnection() {
        Connection conn = Jdbcutils.getConnection();
        System.out.println(conn);
    }

}

第一個問題:named-config with name 'BarryLee' does not exist也就是找不到名字為BarryLee的confiig

以下是我的c3p0-config.xml的配置代碼(最后修改完畢的)

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
    <!-- 默認配置,如果沒有指定則使用這個配置 -->
    <default-config>
        <property name="driverClass">com.mysql.cj.jdbc.Driver</property>
        <property name="jdbcUrl">
            <![CDATA[jdbc:mysql://localhost:3306/mvcproject?useUnicode=true&characterEncoding=utf8&use=true&useSSL=false&serverTimezone=GMT]]>
        </property>
        <property name="user">root</property>
        <property name="password">XXXXXXX</property>
        <!-- 初始化池大小 -->
        <property name="initialPoolSize">2</property>
        <!-- 最大空閑時間 -->
        <property name="maxIdleTime">30</property>
        <!-- 最多有多少個連接 -->
        <property name="maxPoolSize">10</property>
        <!-- 最少幾個連接 -->
        <property name="minPoolSize">2</property>
        <!-- 每次最多可以執行多少個批處理語句 -->
        <property name="maxStatements">50</property>
    </default-config>
    <!-- 命名的配置 -->
    <named-config name="BarryLee">
        <property name="driverClass">com.mysql.cj.jdbc.Driver</property>
        <property name="jdbcUrl"><![CDATA[jdbc:mysql://localhost:3306/mvcproject?useUnicode=true&characterEncoding=utf8&use=true&useSSL=false&serverTimezone=GMT]]></property>
        <property name="user">root</property>
        <property name="password">XXXXXX</property>
        <property name="acquireIncrement">5</property><!-- 如果池中數據連接不夠時一次增長多少個 -->
        <property name="initialPoolSize">100</property>
        <property name="minPoolSize">50</property>
        <property name="maxPoolSize">1000</property>
        <property name="maxStatements">0</property>
        <property name="maxStatementsPerConnection">5</property> <!-- he's important, but there's only one of him -->
    </named-config>
</c3p0-config>

百度了看了一下前輩們的說法,懂了,是因為我把Xml文件放在lib文件夾下面了,xml文件必須要放在src文件夾下面才會起作用

而在我把這個xml文件放在src文件夾下之后,第二個問題出現了:Establishing SSL connection without server's identity verification is not recommende

 具體給我的警告:

 Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

翻譯之后:根據MySQL5.5.45+、5.6.26+和5.7.6+的要求,如果不設置顯式選項,則默認必須建立SSL連接。為了符合不使用SSL的現有應用程序,verifyServerCertificate屬性設置為“false”。您需要通過設置useSSL=false顯式禁用SSL,或者設置useSSL=true並提供用於服務器證書驗證的信任庫。

發現是在jdbcUrl里面缺了東西,必須要禁用SSL,也就是useSSL=false;

接下來繼續運行便有了第三個錯誤:com.mchange.v2.resourcepool.CannotAcquireResourceException:A ResourcePool could not acquire a resource from its primary factory or source.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM