java database and database connection pool even stepped pit diary (two) ------- database connection pool c3p0

  On the database connection pool, I feel a little frustrated, because finally banning federal funding do not consider that the problem multithreaded ......

  Recommended database connection pool: https://www.cnblogs.com/nuccch/p/8120349.html

  I finally chose c3p0, but can not find the share of the most detailed tutorial, can not solve how to get rid of the log log4j warn of problems.

  Off the net, lost records not want to record the ......

First, the configuration file maven

        <!-- c3p0连接池 -->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.2</version>
        </dependency>

Second, configure the account password information

I chose to use xml configuration file, in src / main / resources folder below

<c3p0-config>
    <!-- 默认数据源 -->
    <default-config>
        <property name="driverClass">com.mysql.jdbc.Driver</property>
        <property name="jdbcUrl">jdbc:mysql://localhost:3306?useSSL=false</property>
        <property name="user">root</property>
        <property name="password">123456</property>
        <property name="minPoolSize">3</property>
        <property name="maxPoolSize">10</property>
        <property name="acquireIncrement">5</property>

    </default-config>


    <!-- 定义带名称的数据源 -->
    <named-config name="OracleDataSource">
        <property name="driverClass">oracle.jdbc.driver.OracleDriver</property>
        <property name="jdbcUrl">jdbc:oracle:thin:@oracle的ip地址:端口号:服务名</property>
        <property name="user">账号</property>
        <property name="password">密码</property>
        <property name="minPoolSize">3</property>
        <property name="maxPoolSize">11</property>
        <property name="acquireIncrement">5</property>
    </named-config>


</c3p0-config>

Three, java call

the try {
     Private the DataSource DS;
     // DS = ComboPooledDataSource new new (); // local MySQL 
    DS = new new ComboPooledDataSource ( "the OracleDataSource"); // Oracle 
    Connection connection = ds.getConnection ();
     // obtained after connection operation can be performed sql a 
} the catch (SQLException E) { 
     e.printStackTrace (); 
}

Fourth, multi-threaded calls to the database connection pool

reference

Guess you like

Origin www.cnblogs.com/liwxmyself/p/11606276.html