Hibernate uses the c3p0 data source,

Source: Internet
Author: User

Hibernate uses the c3p0 data source,
After configuring hibernate to connect to the database environment, we can perform the following operations to build the environment for using the c3p0 data source in hibernate. 1). Import the jar package:
Hibernate-release-4.2.4.Final \ lib \ optional \ c3p0 \ *. jar (here there are generally 3 jar packages) c3p0-0.9.2.1.jar
Hibernate-c3p0-4.2.15.Final.jar
Mchange-commons-java-0.2.3.4.jar

2) Add the configuration (added in the hibernate. cfg. xml file ):
Hibernate. c3p0. max_size: Maximum number of connections in the database connection pool hibernate. c3p0. min_size: Minimum number of connections in the database connection pool hibernate. c3p0. acquire_increment: How many databases are connected to hibernate at the same time when the connections in the database connection pool are exhausted. c3p0. timeout: after the connection object in the database connection pool is not used for a long time, hibernate should be destroyed. c3p0. idle_test_period: indicates how long the connection pool detection thread times out to detect all connected objects in the pool. the connection pool itself does not remove itself from the connection pool. Instead, a thread is dedicated to doing this at a certain interval, this thread compares the time difference between the last used time and the current time of the connected object with timeout to determine whether to destroy the connected object. Hibernate. c3p0. max_statements: Number of cached Statement objects
The following is the original configuration code: the following code is added to the hibernate. cfg. xml file.

</Pre> <pre name = "code" class = "html"> <! -- Configure the c3p0 data source --> <property name = "hibernate. c3p0. max_size "> 10 </property> <property name =" hibernate. c3p0. min_size "> 2 </property> <property name =" c3p0. acquire_increment "> 2 </property> <property name =" c3p0. idle_test_period "> 2000 </property> <property name =" c3p0. timeout "> 2000 </property> <property name =" c3p0. max_statements "> 10 </property>

We can write test cases to check whether the building is successful: Create a junit test case, re-write the dowork method in the test case to call the connection object in jdbc, and print it out.
@ Testpublic void testDoWork () {session. doWork (new Work () {@ Overridepublic void execute (Connection connection) throws SQLException {System. out. println (connection); // call the stored procedure .}});}

If the following code with c3p0 is printed, it indicates that it has been successfully set up.
com.mchange.v2.c3p0.impl.NewProxyConnection@5848ddac





Related Article

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.