Open source data sources use DBCP and C3PO

Source: Internet
Author: User
Tags time in milliseconds

Jar Package:

Commons-dbcp-1.4.jar

Commons-pool-1.5.6.jar

Mysql-connector-java-5.0.8-bin.jar

Establish DBCP configuration file dbcpconfig.properties

<dbcpconfig.properties>

#连接设置
Driverclassname=com.mysql.jdbc.driver
Url=jdbc:mysql://localhost:3306/jdbc
Username=root
password=

#<!--Initialize the connection--
initialsize=10

#最大连接数量
Maxactive=50

#<!--Maximum idle connection--
Maxidle=20

#<!--Minimum idle connection--
Minidle=5

#<!--Timeout Wait time in milliseconds of 6000 milliseconds/1000 equals 60 seconds--
maxwait=60000


#JDBC驱动建立连接时附带的连接属性属性的格式必须为这样: [attribute name =property;]
#注意: The two properties of "User" and "password" are explicitly passed, so there is no need to include them here.
Connectionproperties=useunicode=true;characterencoding=gbk

#指定由连接池所创建的连接的自动提交 (Auto-commit) state.
Defaultautocommit=true

#driver default Specifies the read-only (read-only) state of the connection created by the connection pool.
#如果没有设置该值, the "setreadonly" method will not be called. (Some drivers do not support read-only mode, such as: Informix)
defaultreadonly=

#driver default Specifies the transaction level (transactionisolation) of the connection created by the connection pool.
#可用值为下列之一: (Details visible Javadoc. ) none,read_uncommitted, read_committed, Repeatable_read, SERIALIZABLE
defaulttransactionisolation=read_uncommitted

</dbcpconfig.properties>

Writing Custom Dbcputil Classes

Ok!

C3P0 use steps as consistent

Copy jar Package:

C3p0-0.9.1.2.jar

C3p0-0.9.1.2-jdk1.3.jar (This jar package is not available)

C3p0-oracle-thin-extras-0.9.1.2.jar (Oracle database dedicated)

Configuration file

1.1. XML format

1.2.properties file Format (skip)

1.3. Set (Combopooleddatasource) Setxxxx property in the class that created the data source

2 Creating the C3p0util class provides the connection method

public class c3p0{

Combopooleddatasource ds=new combopooleddatasource ("parameter");

public static Connection getconnection () {

return Ds.getconnection ();

}

public static DataSource Getdatasource () {

return DS;

}

Parameter description Gets the default configuration in the configuration file if the parameter is not written

If the write parameter is written to the value of the Name property of Name-config in config

}

Open source data sources use DBCP and C3PO

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.