Obtain datasource from the proxool database connection pool

Source: Internet
Author: User

Common Configuration

 

Proxool. xml file:

 

 

<? XML version = "1.0" encoding = "UTF-8"?>

<Proxool-config>

<Proxool>

<Alias> dB </alias>

<Driver-URL> JDBC: mysql: /// localhost: 3306/TT </driver-URL>

<Driver-class> com. MySQL. JDBC. Driver </driver-class>

<Driver-Properties>

<Property name = "user" value = "root"/>

<Property name = "password" value = "paulyun2001"/>

</Driver-Properties>

<House-keeping-sleep-time> 9000

<Maximum-New-connections> 20 </maximum-New-connections>

<Prototype-count> 5 </prototype-count>

<Maximum-connection-count> 100 </maximum-connection-count>

<Minimum-connection-count> 10 </minimum-connection-count>

</Proxool>

</Proxool-config>

 

 

Code:


/**
* Common configuration file implementation method, using proxool. xml configuration
*/
Proxooldatasource = NULL;
Try {
Class. forname ("org. logicalcobwebs. proxool. proxooldriver ");
Jaxpconfigurator. Configure (New inputstreamreader (performancefactory. Class. getclassloader ().

Getresourceasstream ("proxool. xml"), false );
Proxooldatasource = new proxooldatasource ("DB ");

} Catch (proxoolexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (classnotfoundexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}

 

Spring Configuration

 

<Bean id = "datasource"

Class = "org. logicalcobwebs. proxool. proxooldatasource" Scope = "Singleton">

<Property name = "driver">

<Value> com. MySQL. JDBC. Driver </value>

</Property>

<Property name = "driverurl">

<Value> JDBC: mysql: // localhost: 3306/TT </value>

</Property>

<Property name = "user" value = "root"/>

<Property name = "password" value = "paulyun2001"/>

<! -- <Property name = "alias" value = "pool_dbname"/> -->

<! -- <Property name = "housekeepingsleeptime" value = "90000" type = "parmname" text = "parmname"/> -->

<Property name = "prototypecount" value = "10"/>

<! -- <Property name = "maximumconnectioncount" value = "50"/> -->

<! -- <Property name = "minimumconnectioncount" value = "2"/> -->

<! -- <Property name = "simultaneousbuildthrottle" value = "50"/> -->

<! -- <Property name = "maximumconnectionlifetime" value = "100000"/> -->

<! -- <Property name = "housekeepingtestsql" value = "select current_date"/> -->

</Bean>

The comments can be left empty, which is the default value.

 

Code:

 

/**

* The Spring implementation method uses the applicationcontext. xml configuration.

*/

Beanfactory factory = new classpathxmlapplicationcontext ("applicationcontext. xml ");

Proxooldatasource datasource = (proxooldatasource) Factory. getbean ("datasource ");

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.