解决java.net.SocketException: Broken pipe异常

出现如下异常
解决的方式:参考hibernate配置文件:
	<!--MySql 驱动程序 eg. mysql-connector-java-5.0.4-bin.jar-->
	<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
	<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

	<!-- JDBC URL -->
	<property name="connection.url">
		jdbc:mysql://localhost/tonyshao?characterEncoding=gb2312&amp;zeroDateTimeBehavior=convertToNull
	</property>

	<property name="connection.username">user</property>
	<property name="connection.password">passport</property>

	<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
	<property name="hibernate.cache.use_query_cache">true</property>
	
	<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> 
	<property name="hibernate.connection.pool_size">2</property>
	<!--连接关闭时默认将所有未提交的操作回滚。Default: false -->
	<property name="hibernate.connection.autocommit">false</property>
	
	<!-- c3p0 connection pooling properties -->
    <!-- 数据库连接对象最大持有时间,这个timeout一定要大于MYSQL默认的28800(秒) -->
    <property name="c3p0.timeout">30000</property>
    <!-- 最大可缓存数据库语句对象 -->
    <property name="c3p0.max_statements">50</property>
    <!-- 每隔28000s测试连接是否可用 -->
    <property name="c3p0.idle_test_period">28000</property>
    <property name="c3p0.acquire_increment">1</property>
 
Last packet sent to the server was 1 ms ago.

STACKTRACE:

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException
MESSAGE: Broken pipe

STACKTRACE:

java.net.SocketException: Broken pipe
	at java.net.SocketOutputStream.socketWrite0(Native Method)
	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
	at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
	at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
	at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2692)
	at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2621)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1552)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030)
	at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
	at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
	at org.hibernate.loader.Loader.doQuery(Loader.java:662)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
	at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)

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