C3P0: database connection pool technology

Step:
    1. Import jar package (two) c3p0-0.9.5.2.jar, mchange-Commons-Java-0.2.12.jar,
      * do not forget to import database driver jar package
    2. Define profiles:
      * Name: c3p0. properties-config.xml or c3p0
      * path: directly to files in the src directory.

    3. Create a core object database connection pool object ComboPooledDataSource
    4. Get connected: the getConnection
          * Code:
            // Create a database connection pool object.
            The DataSource ComboPooledDataSource new new DS = ();
            // get a connection objects 2.
            Connection ds.getConnection Conn = ( );

    Profiles:

< The c3p0-config > 
  <-! Default configuration read connection pool object -> 
  < default-config > 
      <-!   Connection parameter -> 
    < Property name = "driverClass" > com.mysql.jdbc.Driver </ Property > 
    < Property name = "the jdbcUrl" > JDBC: MySQL: // localhost: 3306 / Demo </ Property > 
    < Property name = "User" > the root </ Property > 
    < Property name = "password">123456</ Property > 
    
    <! - connection pool parameters -> 
    <! - The initial number of connection pool application -> 
    < Property name = "initialPoolSize" > . 5 </ Property > 
    - <! Maximum number of connections - > 
    < Property name = "the maxPoolSize" > 10 </ Property > 
    <-! timeout milliseconds -> 
    < Property name = "checkoutTimeout" > 3000 </ Property > 
  </ default-config >

  <named-config name="otherc3p0"> 
    <!--  连接参数 -->
    <property name="driverClass">com.mysql.jdbc.Driver</property>
    <property name="jdbcUrl">jdbc:mysql://localhost:3306/demo</property>
    <property name="user">root</property>
    <property name="password">123456</property>
    
    <!- <->connection pool parameters
    property name="initialPoolSize">5</property>
    <property name="maxPoolSize">8</property>
    <property name="checkoutTimeout">1000</property>
  </named-config>
</c3p0-config>

 

Guess you like

Origin www.cnblogs.com/naigai/p/11797646.html