jdbc串連池中c3p0的設定檔的詳解以及在在java中如何使用

來源:互聯網
上載者:User

標籤:shc   char   encoding   system   stat   127.0.0.1   處理   out   多少   

<c3p0-config>
<!-- 預設配置,如果沒有指定則使用這個配置 -->
<default-config>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">
<![CDATA[jdbc:mysql://127.0.0.1:3306/hncu?useUnicode=true&characterEncoding=UTF-8]]>
</property>
<property name="user">root</property>
<property name="password">1234</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="hncu"><!--這裡是設定設定檔的名字-->
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">
<![CDATA[jdbc:mysql://127.0.0.1:3306/hncu?useUnicode=true&characterEncoding=UTF-8]]><!--這個設定是<![CDATA[...]]是原樣輸出不會進行解析-->
</property>
<property name="user">root</property><!--mysql的登陸名-->
<property name="password">1234</property><!--如果沒密碼就可以設定成<property name="password"></property>-->
<property name="acquireIncrement">5</property><!-- 如果池中資料連線不夠時一次增長多少個 -->
<property name="initialPoolSize">10</property>
<property name="minPoolSize">5</property>
<property name="maxPoolSize">15</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>
-------------------------------------------------------------------------------------------------------------------------------------------

 import com.mchange.v2.c3p0.ComboPooledDataSource; 

ComboPooledDataSource pool=new ComboPooledDataSource();
System.out.println(pool.getProperties());//這裡可以輸出mysql的使用者名稱和密碼;
for(int i=0;i<15;i++){
Connection con=pool.getConnection();
System.out.println(con.hashCode());//這裡是輸出串連的地址。
}

 

jdbc串連池中c3p0的設定檔的詳解以及在在java中如何使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.