<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>
 
 <property name="url" value="jdbc:jtds:sqlserver://192.168.0.133:1433;DatabaseName=cc"/>
<property name="username" value="cc"/>
 <property name="password" value="cc"/>
 <!-- Connection Pooling Info -->
  <property name="initialSize" value="5" />
  <property name="maxActive" value="100" />
  <property name="maxIdle" value="30" />
  <property name="maxWait" value="1000" />
  <property name="poolPreparedStatements" value="true" />
  <property name="defaultAutoCommit" value="false" />
</bean>
费解啊  只要加上   
<property name="initialSize" value="5" />
  <property name="maxActive" value="100" />
  <property name="maxIdle" value="30" />
  <property name="maxWait" value="1000" />
  <property name="poolPreparedStatements" value="true" />
  <property name="defaultAutoCommit" value="false" />
就有问题 去掉 就可以正常运行

解决方案 »

  1.   

    我想在spring  applicationContext-common.xml里保持几个连接 这样操作数据库就不用频繁连接数据库了。
      

  2.   

    楼主 你用错了!
    给你看一段关于这个类的用途吧
    NOTE: This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call. org.springframework.jdbc.datasource.DriverManagerDataSource不包含一下属性,当然你就不能注入了
     <!-- Connection Pooling Info -->
     <property name="initialSize" value="5" />
     <property name="maxActive" value="100" />
     <property name="maxIdle" value="30" />
     <property name="maxWait" value="1000" />
     <property name="poolPreparedStatements" value="true" />
     <property name="defaultAutoCommit" value="false" />
    你如果要用连接池: 你可以用DHCP 或者 C3PO的数据源 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/news"/>
            <property name="username" value="root"/>
            <property name="password" value="1234"/>
            <property name="maxActive" value="20"/>
            <property name="maxIdle" value="10"/>
            <property name="initialSize" value="1"/>
            <property name="maxWait" value="1000"/>
            <property name="defaultAutoCommit" value="true"/>
            <property name="removeAbandoned" value="true"/>
            <property name="removeAbandonedTimeout" value="60"/>
            <property name="logAbandoned" value="true"/>
        bean>  或者 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
       <property name="driverClass" value="${jdbc.driverClass}" />
       <property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
       <property name="user" value="${jdbc.user}" />
       <property name="password" value="${jdbc.password}" />
       <property name="minPoolSize" value="${jdbc.miniPoolSize}" />
       <property name="maxPoolSize" value="${jdbc.maxPoolSize}"/>  
       <property name="initialPoolSize" value="${jdbc.initialPoolSize}"/>
       <property name="maxIdleTime" value="${jdbc.maxIdleTime}"/>
       <property name="acquireIncrement" value="${jdbc.acquireIncrement}"/>
      
       <property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}"/>
       <property name="acquireRetryDelay" value="${jdbc.acquireRetryDelay}"/>
       <property name="testConnectionOnCheckin" value="${jdbc.testConnectionOnCheckin}"/>
       <property name="automaticTestTable" value="${jdbc.automaticTestTable}"/>
       <property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}"/>
       <property name="checkoutTimeout" value="${jdbc.checkoutTimeout}"/></bean>