在Spring中使用JNDI数据源
在tomcat6通创建基于jtds驱动的c3p0数据源
<Resource name="jdbc/test" auth="Container" type="com.mchange.v2.c3p0.ComboPooledDataSource" description="DB Connection" factory="org.apache.naming.factory.BeanFactory" driverClass="net.sourceforge.jtds.jdbc.Driver" jdbcUrl="jdbc:jtds:sqlserver://localhost:1433/dbname" user="sa" password="" maxPoolSize="10" minPoolSize="2" acquireIncrement="2" />
在Spring中配置JNDI数据源
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>java:comp/env/jdbc/test</value> </property> </bean>
在Spring中创建数据源
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" dependency-check="none"> <property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:jtds:sqlserver://localhost:1433/test" /> <property name="properties"> <props> <prop key="c3p0.minPoolSize">5</prop> <prop key="hc3p0.maxPoolSize">10</prop> <prop key="hc3p0.timeout">60</prop> <prop key="c3p0.max_statement">50</prop> <prop key="c3p0.testConnectionOnCheckout">true</prop> <prop key="user">sa</prop> <prop key="password"></prop> </props> </property> </bean>