Hibernate+MySQL部署出现了java.net.SocketException: Broken pipe (Write failed)这个错误,查百度说是因为MySQL默认连接8小时的问题,所以想采用C3P0,附上Hibernate.xml配置如下:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="myeclipse.connection.profile">sces</property>
<property name="connection.url"><![CDATA[jdbc:mysql://localhost:3306/sces?useUnicode=true&characterEncoding=UTF-8]]></property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.password">123456</property>
<property name="connection.username">root</property>
<!--c3p0设置-->
<!--<property name="connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>-->
<!--<property name="hibernate.c3p0.min_size">5</property>-->
<!--<property name="hibernate.c3p0.max_size">20</property>-->
<!--<property name="hibernate.c3p0.max_statements">100</property>-->
<!--<property name="hibernate.c3p0.timeout">3600</property>-->
<!--<property name="hibernate.c3p0.idle_test_period">120</property>-->
<!--<property name="hibernate.c3p0.acquire_increment">2</property>-->
<mapping resource="entity/DCharacteristic.hbm.xml" />
<mapping resource="entity/DIops.hbm.xml" />
<mapping resource="entity/DPool.hbm.xml" />
<mapping resource="entity/DStatus.hbm.xml" />
<mapping resource="entity/Device.hbm.xml" />
<mapping resource="entity/User.hbm.xml" />
<mapping resource="entity/DDl.hbm.xml" />
<mapping resource="entity/Systeminfo.hbm.xml" />
<mapping resource="entity/DCapacity.hbm.xml"/>
<mapping resource="entity/DErrlog.hbm.xml"/>
<mapping resource="entity/DRack.hbm.xml"/>
</session-factory>
</hibernate-configuration>
中间注释掉的为c3p0的部分,现在这种情况下能正常运行,但是打开c3p0后会报错:
十二月 26, 2017 3:02:49 下午 com.mchange.v2.resourcepool.BasicResourcePool
警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@58f663e4 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:278)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
看起来是找不到驱动,但是明明不开连接池的时候能正常跑的,说明驱动没问题呀,为什么会这样呢
补充:直接在IDE中运行读取数据库的操作可以正常运行,但是把程序放到tomcat中就会
报这个错误,MySQL的驱动在tomcat的bin和lib中都放了,求解!!!!!