我想知道如何将 tomcat 连接到 oracle jdbc 池

I wonder how can I connect tomcat to oracle jdbc pool

我的代码对吗? 在 context.xml 我这样添加。也许 driveClassName 或 url 有问题?

<Resource  name="jdbcoracle"   auth="Container" type="javax.sql.DataSource"
 factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
maxActive="20"
maxIdle="1"
maxWait="100"
username="test"
password="test"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:8080/orcl"/>   

in web.xml in both tomcat and project add like this

<resource-ref> 
<description>oracle Connection</description> 
<res-ref-name>jdbc/oracle</res-ref-name> 
<res-type>javax.sql.DataSource</res-type> 
<res-auth>Container</res-auth> 
</resource-ref>

但看起来仍然是

javax.servlet.ServletException: javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]

那我该怎么办?顺便说一句,我将 tomcat 端口号更改为 8081,因为 8080 不起作用。

您错过了类路径中的 tomcat-dbcp.jar。下载并将其添加到类路径中。

根据 the reference 这看起来不错,但有一个例外(如果你只是 copied/pasted 你的声明):

在你的 <Resource> 声明中你有 name="jdbcoracle" 而在你的 <resource-ref> 中你使用 jdbc/oracle - 注意斜线。

我在最初回答后 8 小时才看到这个:您声明数据库 URL 指向端口 8080 - 这通常是一个管理界面(也是 tomcat 不能在这个端口上 运行),而 Oracle 的数据库端口以前是 1521(除非你改变了它)。

此外,按照 Jens 在他的回答中建议的那样检查您的类路径。

参考白皮书。此处为 Tomcat 的通用连接池 (UCP)。 http://www.oracle.com/technetwork/database/application-development/planned-unplanned-rlb-ucp-tomcat-2265175.pdf