我应该在数据库MySQL中存储大量的pdf文件。我使用了与MySQL的c3p0连接池。配置如下。
<?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">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.max_size">300</property>
<property name="hibernate.c3p0.acquire_increment">10</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.idle_test_period">600</property>
<property name="hibernate.c3p0.timeout">1200</property>
<property name="hibernate.c3p0.maxIdleTimeExcessConnections">600</property>
<property name="connection.autoReconnect"> true</property>
<property name="connection.autoReconnectForPools">true</property>
<!-- property name="hibernate.jdbc.batch_size"> 4 </property-->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="com.pojo.PDFDetails"/>
</session-factory>
</hibernate-configuration>
导入6个或有时7个pdf后,我遇到以下异常:
--[001_KL695627797FT.pdf, 002_KL695627655FT.pdf, 003_KL695627505FT.pdf, 004_MN574152846FT.pdf, 005_SE082789582FT.pdf, 006_KL848699892FT.pdf]---
G:\Phase II Scanning\ABX1185 to ABX1260\ABX1185\ABN4737\006_KL848699892FT.pdf 006_KL848699892FT.pdf
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at com.pojo.HibUtil.storeInDb(HibUtil.java:32)
at monitor.MonitorPdf.callList(MonitorPdf.java:97)
at monitor.MonitorPdf.callList(MonitorPdf.java:84)
at monitor.MonitorPdf.callList(MonitorPdf.java:84)
at monitor.MonitorPdf.callList(MonitorPdf.java:84)
at monitor.MonitorPdf.cleanPDFDir(MonitorPdf.java:31)
at monitor.MonitorPdf.main(MonitorPdf.java:14)
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
... 11 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 14 more
我的c3p0 jar版本是0.9.1.2 有人可以帮我吗?请避免猜测。