Spring with c3p0 connection pool

Source: Internet
Author: User
Spring with C3P0 connection pool applicationContext. xml file:
<? Xml version = "1.0" encoding = "UTF-8"?> <Br/> <beans xmlns = "http://www.springframework.org/schema/beans" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xmlns: jee = "http://www.springframework.org/schema/jee" <br/> xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/j Ee/spring-jee-2.0.xsd "> <br/> <bean id =" dataSource "class =" com. mchange. v2.c3p0. comboPooledDataSource "destroy-method =" close "> <br/> <property name =" driverclass "> <br/> <value> com. mysql. jdbc. driver </value> <br/> </property> <br/> <property name = "jdbcUrl"> <br/> <value> jdbc: mysql: // 192.168.3.110: 3306/DBName? UseUnicode = true & characterEncoding = GBK </value> <br/> </property> <br/> <property name = "user"> <br/> <value> root </value> <br/> </property> <br/> <property name = "password"> <br/> <value> root </value> <br/> </property> </p> <! -- The minimum number of connections retained in the connection pool. --> <Br/> <property name = "minPoolSize"> <br/> <value> 5 </value> <br/> </property> </p> <p> <! -- The maximum number of connections retained in the connection pool. Default: 15 --> <br/> <property name = "maxPoolSize"> <br/> <value> 30 </value> <br/> </property> </p> <p> <! -- The number of connections obtained during initialization. The value must be between minPoolSize and maxPoolSize. Default: 3 --> <br/> <property name = "initialPoolSize"> <br/> <value> 10 </value> <br/> </property> </p> <p> <! -- Maximum idle time. connections are dropped if they are not used within 60 seconds. If it is 0, it will never be discarded. Default: 0 --> <br/> <property name = "maxIdleTime"> <br/> <value> 60 </value> <br/> </property> </p> <p> <! -- The number of connections that c3p0 obtains at the same time when connections in the connection pool are exhausted. Default: 3 --> <br/> <property name = "acquireIncrement"> <br/> <value> 5 </value> <br/> </property> </p> <p> <! -- JDBC standard parameter, used to control the number of PreparedStatements loaded in the data source. However, the pre-cached statements belong to a single connection rather than the entire connection pool. Therefore, you need to consider many factors when setting this parameter. If both maxStatements and maxStatementsPerConnection are 0, the cache is disabled. Default: 0 --> <br/> <property name = "maxStatements"> <br/> <value> 0 </value> <br/> </property> </p> <p> <! -- Check all idle connections in the connection pool every 60 seconds. Default: 0 --> <br/> <property name = "idleConnectionTestPeriod"> <br/> <value> 60 </value> <br/> </property> </p> <p> <! -- Defines the number of repeated attempts after a new connection fails to be obtained from the database. Default: 30 --> <br/> <property name = "acquireRetryAttempts"> <br/> <value> 30 </value> <br/> </property> </p> <p> <! -- Failed to obtain the connection will cause all threads waiting for the connection pool to obtain the connection to throw an exception. However, the data source is still valid, and the next call to getConnection () will continue to get the connection. If it is set to true, the data source will be declared disconnected and permanently closed after the connection fails to be obtained. Default: false --> <br/> <property name = "breakAfterAcquireFailure"> <br/> <value> true </value> <br/> </property> </p> <p> <! -- Because of high performance consumption, use it only when needed. If it is set to true, the validity of each connection is verified when it is submitted. We recommend that you use idleConnectionTestPeriod or automaticTestTable to improve the connection test performance. Default: false --> <br/> <property name = "testconnectioncheckout"> <br/> <value> false </value> <br/> </property> <br/> </bean> <br/> <! -- Hibernate SessionFactory --> <br/> <bean id = "sessionFactory" class = "org. springframework. orm. hibernate3.LocalSessionFactoryBean "> <br/> <property name =" dataSource "> <br/> <ref local =" dataSource "/> <br/> </property> <br/> <property name = "mappingResources"> <br/> <list> <br/> <value> com/xh/hibernate/vo/User. hbm. xml </value> <br/> </list> <br/> </property> <br/> <property name = "hibernateProperties"> <br/> <props> <br/> <prop key = "hibernate. dialect "> org. hibernate. dialect. mySQLDialect </prop> <br/> <prop key = "hibernate. show_ SQL "> true </prop> <br/> <prop key =" hibernate. generate_statistics "> true </prop> <br/> <prop key =" hibernate. connection. release_mode "> auto </prop> <br/> <prop key =" hibernate. autoReconnect "> true </prop> <br/> </props> <br/> </property> <br/> </bean> <br/> </beans>Article Source: http://www.javaeedev.com/blog/article.jspx? ArticleId = ff8080811a2a52f2011a383e5baf09da

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.