Tomcat连接池,为web-app安装jdbc驱动程序 [英] Tomcat connection pooling, install jdbc driver for web-app

查看:355
本文介绍了Tomcat连接池,为web-app安装jdbc驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个以 Tomcat 6 作为容器的网络应用程序,我正在尝试使用连接池。我正在使用的jdbc驱动程序是 jtds-1.2.2

当驱动程序jar放在 $ {Catalina_Home} / lib下时,池工作正常,但我的托管服务提供商不允许我这样做。

I am making a web-app with Tomcat 6 as the container and I'm trying to use connection pooling. The jdbc driver I am using is jtds-1.2.2.
The pool works fine when the driver jar is placed under ${Catalina_Home}/lib, but my hosting provider would not let me do so.

当驱动程序放在<$ c中时,我得到CNF异常$ c> WEB-INF / lib 。

有人可以提供我无需访问tomcat安装的解决方案吗? / p>

Could someone please provide a solution where I won't have to access the tomcat installation?

推荐答案

如果你无法控制服务器,那么你就输了。只需自己创建连接池,而不是让容器执行它。

If you don't have control over the server, then you're lost. Just create the connection pool yourself instead of letting the container do it.

我建议使用 c3p0 (这比Tomcat的内置DBCP好得多,因为它被锁定到一个线程)。将c3p0库放在 / WEB-INF / lib 中,并按其文档

I suggest to use c3p0 for this (which is far better than Tomcat's builtin DBCP since it's locked to a single thread). Put the c3p0 libraries in the /WEB-INF/lib and create it as per its documentation:

ComboPooledDataSource dataSource = new ComboPooledDataSource(); 
dataSource.setDriverClass("org.postgresql.Driver"); 
dataSource.setJdbcUrl("jdbc:postgresql://localhost/testdb");
dataSource.setUser("dbuser");
dataSource.setPassword("dbpassword"); 
// ...

Connection connection = null;
// ...
try {
    connection = dataSource.getConnection();
    // ...
} finally {
    // ...
    if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {} // Always close resources in finally!
}

这篇关于Tomcat连接池,为web-app安装jdbc驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆