直接上配置: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"> </property> <property name="url" value="jdbc:mysql://127.0.0.1:3306/"></property> <property name="username" value="root"></property> <property name="password" value="abc"></property> </bean> --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>com.mysql.jdbc.Driver</value> </property> <property name="jdbcUrl"> <value>jdbc:mysql://127.0.0.1:3306/ithink_logger</value> </property> <property name="user"> <value>root</value> </property> <property name="password"> <value>abc</value> </property> <!-- 当连接池中的连接用完时,C3P0一次性创建新连接的数目。默认为3 --> <property name="acquireIncrement"> <value>3</value> </property> <!-- 初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。默认为3 --> <property name="initialPoolSize"> <value>5</value> </property> <!-- 连接池中保留的最小连接数 --> <property name="minPoolSize"> <value>2</value> </property> <!-- 连接池中保留的最大连接数。默认为15 --> <property name="maxPoolSize"> <value>100</value> </property> <!-- 最大空闲时间,超过空闲时间的连接将被丢弃。为0或负数则永不丢弃。默认为0秒 --> <property name="maxIdleTime"> <value>30</value> </property> <!--每60秒检查所有连接池中的空闲连接。Default: 0 --> <property name="idleConnectionTestPeriod"> <value>60</value> </property> <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。 如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 --> <property name="maxStatements"> <value>100</value> </property> <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 --> <property name="maxStatementsPerConnection"> <value>200</value> </property> <property name="numHelperThreads"> <value>10</value> </property> <!-- 定义在从数据库获取新连接失败后重复尝试获取的次数,默认为30 --> <property name="acquireRetryAttempts"> <value>30</value> </property> <!-- 连接关闭时默认将所有未提交的操作回滚。默认为false --> <property name="autoCommitOnClose"> <value>false</value> </property> <!--两次连接中间隔时间,单位毫秒。Default: 1000 --> <property name="acquireRetryDelay"> <value>100</value> </property> <!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试 获取连接失败后该数据源将申明已断开并永久关闭。Default: false --> <property name="breakAfterAcquireFailure"> <value>false</value> </property> <!-- 当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出SQLException,如设为0则无限期等待。单位毫秒,默认为0 --> <property name="checkoutTimeout" value="10000" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> <property name="mappingResources"> <list> <value>com/ithink/pojo/ItkStat.hbm.xml</value> <value>com/ithink/pojo/ItkCount.hbm.xml</value> </list> </property> </bean> <bean id="ItkCountDAO" class="com.ithink.pojo.ItkCountDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="ItkStatDAO" class="com.ithink.pojo.ItkStatDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> </beans> ItkCount.hbm.xml <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="com.ithink.pojo.ItkCount" table="itk_count" catalog="ithink_logger"> <id name="id" type="integer"> <column name="id" /> <generator class="identity" /> </id> <property name="imei" type="string"> <column name="imei" length="45" /> </property> <property name="name" type="string"> <column name="name" length="100" /> </property> <property name="sum" type="integer"> <column name="sum" /> </property> </class> </hibernate-mapping> ItkStat.hbm.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="com.ithink.pojo.ItkStat" table="itk_stat" catalog="ithink_logger"> <id name="id" type="integer"> <column name="id" /> <generator class="identity" /> </id> <property name="imei" type="string"> <column name="imei" length="45" /> </property> <property name="name" type="string"> <column name="name" length="100" /> </property> <property name="msg" type="string"> <column name="msg" /> </property> <property name="time" type="timestamp"> <column name="time" length="19" /> </property> <property name="level" type="string"> <column name="level" length="10" /> </property> </class> </hibernate-mapping> DAO层是myeclipse 10直接hibnerate逆向出来的 数据库的连接很快就到100+, 然后就连接不上,但是过一会,大概10S左右,就可以连接了, 楼主小白,求赐教 |
|
40分 |
</property>
<!– 当连接池中的连接用完时,C3P0一次性创建新连接的数目。默认为3 –> <property name=”acquireIncrement”> <value>3</value> </property> <!– 初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。默认为3 –> <property name=”initialPoolSize”> <value>5</value> </property> <!– 连接池中保留的最小连接数 –> <property name=”minPoolSize”> <value>2</value> </property> <!– 连接池中保留的最大连接数。默认为15 –> <property name=”maxPoolSize”> <value>100</value> </property> ————— 应该是你的这几个参数值的原因吧,你重新设置一下这几个值然后测试试试? |
问题已经解决了,谢谢楼上的答复
|