程空万里 2015-02-10
由于maven无法直接使用sqljdbc4.jar来连接SqlServer,因此使用jtds和c3p0来替代。
具体做法:
1. 加入pom依赖
<dependency> <groupId>net.sourceforge.jtds</groupId> <artifactId>jtds</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> </dependency>
2. 在src/main/resources下加入c3p0-config.xml
<c3p0-config> <default-config> <property name="driverClass">net.sourceforge.jtds.jdbc.Driver</property> <property name="jdbcUrl">jdbc:jtds:sqlserver://localhost:1433/mydb </property> <property name="user">sa</property> <property name="password">Admin123</property> <property name="acquireIncrement">50</property> <property name="initialPoolSize">100</property> <property name="minPoolSize">50</property> <property name="maxPoolSize">1000</property> </default-config> <named-config name="mydb"> <property name="driverClass">net.sourceforge.jtds.jdbc.Driver</property> <property name="jdbcUrl">jdbc:jtds:sqlserver://127.0.0.1:1433/mydb </property> <property name="user">sa</property> <property name="password">Admin123</property> <property name="checkoutTimeout">30000</property> <property name="idleConnectionTestPeriod">30</property> <property name="initialPoolSize">10</property> <property name="maxIdleTime">30</property> <property name="maxPoolSize">100</property> <property name="minPoolSize">10</property> <property name="maxStatements">200</property> </named-config> </c3p0-config>
3.测试