com.mysql.jdbc.exceptions MySQLNonTransientConnectionException

启动工程后,开始运行正常,但运行一段时间访问量稍微变大后控制台会报错:

 

1.  org.hibernate.exception.JDBCConnectionException: could not execute query    
   2. at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)    
   3. at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)    
   4. .......    
   5. Caused by: com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:    
   6.   
   7.   
   8. ** BEGIN NESTED EXCEPTION **    
   9.   
  10. com.mysql.jdbc.CommunicationsException    
  11. MESSAGE: Communications link failure due to underlying exception:    
  12.   
  13. ** BEGIN NESTED EXCEPTION **    
  14.   
  15. java.net.SocketException    
  16. MESSAGE: Broken pipe    
  17.   
  18. STACKTRACE:    
  19.   
  20. java.net.SocketException: Broken pipe    
  21. at java.net.SocketOutputStream.socketWrite0(Native Method)    
  22. ......    
  23. ** END NESTED EXCEPTION **    

 

连接池的问题,网上对比 c3p0 表现最好,我们这里也不用dbcp了,改用c3p0,查阅c3p0的文档在官方网站上找不到,注意dbcpc3p0的文档都是在它们的下载包里面,而不是在官方网站上。

 

将配置文件改成c3p0:

<bean id="mysqldb"
		class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass"
			value="com.mysql.jdbc.Driver">
		</property>
		<property name="jdbcUrl"
			value="jdbc:mysql://192.168.1.44:3306/clothes?useUnicode=true&amp;amp;characterEncoding=gbk&amp;amp;characterSetResults=gbk">
		</property>
		<property name="user" value="yourname"></property>
		<property name="password" value="yourpsd"></property>
		<property name="testConnectionOnCheckin" value="true"></property>
		<property name="automaticTestTable" value="testc3p0"></property>
		<property name="idleConnectionTestPeriod" value="18000"></property>
		<property name="maxIdleTime" value="25000"></property>
		<property name="testConnectionOnCheckout" value="true"></property>
		<property name="autoCommitOnClose" value="true"></property>
		<property name="checkoutTimeout" value="30000"></property>
		<property name="initialPoolSize" value="2"></property>
		<property name="minPoolSize" value="2"></property>
		<property name="maxPoolSize" value="5"></property>
		<property name="acquireIncrement" value="1"></property>
		<property name="maxIdleTimeExcessConnections" value="20000"></property>
	</bean>
 问题解决。

 

参考:

http://fishyych.iteye.com/blog/90793

http://azi.iteye.com/blog/182146

http://blog.csdn.net/voff12/archive/2007/06/03/1636344.aspx

http://blog.csdn.net/lip8654/archive/2008/02/26/2121387.aspx

你可能感兴趣的:(mysql,bean,.net,Hibernate,jdbc)