因为工作需要进行proxool链接sql server数据库,正好将配置过程与大家分享
首先是jar包,需要
jtds-1.2.5.jar 对数据库的支持
proxool-0.9.1.jar proxool-cglib.jar 对连接池的支持
<?xml version="1.0" encoding="ISO-8859-1"?>
<something-else-entirely>
<proxool>
<alias>mssql</alias>
<driver-url>jdbc:jtds:sqlserver://127.0.0.1:1433/××××;tds=8.0;lastupdatecount=true;SelectMethod=Cursor</driver-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="sa"/>
<property name="password" value=""/>
</driver-properties>
<maximum-connection-count>20</maximum-connection-count>
<minimum-connection-count>2</minimum-connection-count>
<maximum-active-time>60000</maximum-active-time>
<minimum-connection-count>18000000</minimum-connection-count>
</proxool>
</something-else-entirely>
更多的配置选项可以参考proxool的帮助文档
<servlet>
<servlet-name>ServerConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<param-value>WEB-INF/proxool.xml</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<!--
<servlet>
<servlet-name>admin</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>admin</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>
-->
我注释起来的是对链接池的监听,可以不用配置
想要在本地使用可以用proxool的读取配置文件方法
public static Connection getConnection() {
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
return (Connection) DriverManager.getConnection("proxool.mssql");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static void main(String[] args) throws Exception {
InputStream in = ProxoolDataBase.class
.getResourceAsStream("proxool.xml");
Reader read = null;
read = new InputStreamReader(in);
JAXPConfigurator.configure(read, false);
//JAXPConfigurator.configure("src/org/proxool/proxool.xml", false);
读取文件路径也是好用的
System.out.println(ProxoolDataBase.getConnection().isClosed());
}
可以用proxool中直接设置参数值的方法
private static ProxoolDataSource pds = null;
public static void init() {
pds = new ProxoolDataSource();
pds.setDriver("net.sourceforge.jtds.jdbc.Driver");
pds
.setDriverUrl("jdbc:jtds:sqlserver://127.0.0.1:1433/××××;tds=8.0;lastupdatecount=true;SelectMethod=Cursor");
pds.setUser("sa");
pds.setPassword("");
pds.setAlias("pds");
pds.setMaximumConnectionCount(5);
pds.setMinimumConnectionCount(0);
pds.setMaximumActiveTime(5);
}
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
init();
Connection conn = pds.getConnection();
System.out.println(conn.isClosed());
}
上面的方法都是好用的