添加一下这些,建议封装起来
ApplicationContext ct=new ClassPathXmlApplicationContext("application.xml");
BoneCPDataSource datasource=(BoneCPDataSource)ct.getBean("mainDataSource");
Connection con=datasource.getConnection();
封装就是你可以写到一个方法里面可以多次利用,关闭这个不用担心,连接池会按时间配置自动回收的,这个就是连接池的优点之一
<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource"
destroy-method="close">
<property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="jdbcUrl"
value="jdbc:jtds:sqlserver://localhost:1433/DB_Tools_Manager" />
<property name="username" value="sa" />
<property name="password" value="jsdd12" />
<property name="idleConnectionTestPeriod" value="60" />
<property name="idleMaxAge" value="240" />
<property name="maxConnectionsPerPartition" value="30" />
<property name="minConnectionsPerPartition" value="10" />
<property name="partitionCount" value="3" />
<property name="acquireIncrement" value="5" />
<property name="statementsCacheSize" value="100" />
<property name="releaseHelperThreads" value="3" />
</bean>