How do I change the connection pool of a database into a C3P0 database connection pool? _ Database Connection Pool

Source: Internet
Author: User
Tags aop

First, Hibernate.cfg.xml documents:

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE hibernate-configuration Public
"-//hibernate/hibernate Configuration DTD 3.0//en"
"Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<session-factory>
<property name= "Hibernate.dialect" >org.hibernate.dialect.MySQL5Dialect</property>
<property name= "Hibernate.hbm2ddl.auto" >update</property>
<property name= "Hibernate.show_sql" >true</property>
<mapping resource= "Cn/itcast/elec/domain/electext.hbm.xml"/>
<mapping resource= "Cn/itcast/elec/domain/eleccommonmsg.hbm.xml"/>
<mapping resource= "Cn/itcast/elec/domain/elecsystemddl.hbm.xml"/>
</session-factory>


Second, beans.xml documents:

<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
xmlns:context= "Http://www.springframework.org/schema/context"
xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
xmlns:tx= "Http://www.springframework.org/schema/tx"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd
Http://www.springframework.org/schema/tx
Http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
Http://www.springframework.org/schema/aop
Http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
<!--1: Configuring the scope of the automatic scanning of annotations-->
<context:component-scan base-package= "Cn.itcast.elec" ></context:component-scan>
<!--2: Configure the data source-->
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" >
<property name= "Driverclass" value= "Com.mysql.jdbc.Driver"/>
<property name= "Jdbcurl" value= "jdbc:mysql://localhost:3306/itcast1222elec?useunicode=true&amp; Characterencoding=utf-8 "/>
<property name= "User" value= "root"/>
<property name= "Password" value= "root"/>
<!--the minimum number of connections retained in the connection pool. -->
<property name= "Minpoolsize" value= "5"/>
<!--The maximum number of connections retained in the connection pool. Default:15-->
<property name= "maxpoolsize" value= "/>"
<!--the number of connections obtained when initializing, the value should be between Minpoolsize and Maxpoolsize. Default:3-->
<property name= "Initialpoolsize" value= "ten"/>
<!--maximum idle time, not used within 60 seconds, the connection is discarded. If 0, it will never be discarded. default:0-->
<property name= "maxidletime" value= "/>"
<!--the number of connections that are c3p0 at a time when the connection in the connection pool is depleted. Default:3-->
<property name= "Acquireincrement" value= "5"/>
<!--JDBC Standard parameters to control the number of preparedstatements loaded in the data source. But because of the statements of the cache
belong to a single connection rather than the entire connection pool. So setting this parameter takes into account many factors.
If both maxstatements and maxstatementsperconnection are 0, the cache is closed. Default:0-->
<property name= "maxstatements" value= "0"/>
<!--check for free connections in all connection pools every 60 seconds. default:0-->
<property name= "idleconnectiontestperiod" value= "/>"
<!--defines the number of repeated attempts after a new connection has been failed to get from the database. Default:30-->
<property name= "acquireretryattempts" value= "/>"
<!--getting a connection failure will cause all threads waiting to connect to get the connection to throw an exception. But the data source is still valid
Keep and try to get the connection the next time you call Getconnection (). If set to true, then try the
When a connection fails, the data source declares that it is disconnected and is closed permanently. Default:false-->
<property name= "Breakafteracquirefailure" value= "true"/>
</bean>
<!--3: Create Sessionfactory, which is the portal of spring consolidation hibernate-->
<bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<!--injection configuration data source-->
<property name= "DataSource" ref= "DataSource" ></property>
<property name= "Configlocation" >
<value>
Classpath:hibernate.cfg.xml
</value>
</property>
</bean>
<!--4: Create the transaction manager-->
<bean id= "Txmanage" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" ref= "Sessionfactory" ></property>
</bean>
<!--5: Managing transactions in the form of annotations-->
<tx:annotation-driven transaction-manager= "Txmanage"/>
</beans>

Third, import: C3p0-0.9.1.2.jar rack Package

Download Address: http://download.csdn.net/detail/u013456370/7183803


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.