hibernate 数据库c3p0网络断开的解决方案

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver">
		</property>
		<property name="url" value="jdbc:mysql://10.0.209.184:3306/containerengine?useUnicode=true&amp;characterEncoding=UTF-8">
		</property>
		<property name="username" value="root"></property>
		<property name="password" value="toor"></property>
		<!-- Connection Pooling Info  往下是关键-->
		<property name="initialSize" value="1" />
		<property name="maxActive" value="50" />
		<property name="maxIdle" value="5" />
		<property name="maxWait" value="1000" />
		<property name="poolPreparedStatements" value="true" />
		<property name="defaultAutoCommit" value="false" />
		<property name="validationQuery" ><value>select 1 from c3p0TestTable</value></property>
		<!--removeAbandoned: 是否自动回收超时连接-->  
    	<property name="removeAbandoned" value="true"/>
    	<!--removeAbandonedTimeout: 超时时间(以秒数为单位)-->  
    	<property name="removeAbandonedTimeout" value="180"/> 
    	<property name="testOnBorrow" value="true"></property>
	</bean>

 CREATE TABLE `c3p0TestTable` (
  `ID` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of c3p0TestTable
-- ----------------------------
INSERT INTO `c3p0TestTable` VALUES ('1');

你可能感兴趣的:(Hibernate)