Tomcat连接池,为Web应用程序安装jdbc驱动程序
我正在制作一个以 Tomcat 6 作为容器的网络应用程序,并且我正在尝试使用连接池。我使用的jdbc驱动程序是jtds-1.2.2。
当驱动程序 jar 放置在 ${Catalina_Home}/lib
下时,池工作正常,但我的托管提供商不允许我这样做。
当驱动程序放置在 WEB-INF/lib 中时,我收到 CNF 异常。
有人可以提供一个解决方案,让我不必访问 tomcat 安装吗?
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.
I get a CNF-Exception when the driver is placed in the WEB-INF/lib
.
Could someone please provide a solution where I won't have to access the tomcat installation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您无法控制服务器,那么您就会迷失方向。只需自己创建连接池,而不是让容器来完成。
我建议使用 c3p0 (这比 Tomcat 的内置 DBCP 好得多,因为它被锁定到一个单线程)。将 c3p0 库放入
/WEB-INF/lib
中,并按照 其文档: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.
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:要使用 Tomcat 的连接池,您必须将 JDBC 驱动程序的 jar 复制到
$CATALINA_HOME/lib
中(如 记录),以便驱动程序类通过 通用类加载器否则 DBCP 将无法找到它,因此ClassNotFoundException
。 Tomcat 的类加载器层次结构如下图所示:来自
WEB-INF/lib
的库在通用类加载器中是不可见的(这是一件好事)。如果您无法将驱动程序复制到
$CATALINA_HOME/lib
中,您将无法使用 Tomcat 的连接池。在这种情况下,您必须使用独立的连接池(并将其与WEB-INF/lib
中的驱动程序捆绑在一起)。我在这里第二个BalusC,我会使用C3P0。To use Tomcat's connection pool, you must copy the JDBC Driver's jar into
$CATALINA_HOME/lib
(as documented) so that the driver class is visible through the Common class loader or DBCP won't be able to find it, hence theClassNotFoundException
. Tomcat's class loaders hierarchy is illustrated below:And libraries from
WEB-INF/lib
are not visible from the Common class loader (which is a good thing).If you can't copy your driver into
$CATALINA_HOME/lib
, you won't be able to use Tomcat's connection pool. In that case, you'll have to use a standalone connection pool (and to bundle it along your driver inWEB-INF/lib
). And I second BalusC here, I would use C3P0.