我用的是TOMCAT5.5,首先在D:/Program Files/apache-tomcat-5.5.25/conf/Catalina/localhost路径下加一个XML文件(假设TOMCAT装在D盘下),文件中的内容如下:
<Context>
<Resource name="jdbc/CAAC"
type="javax.sql.DataSource"
username="xsx"
password="xsx"
driverClassName="oracle.jdbc.OracleDriver"
maxIdle="2"
maxWait="5000"
url="jdbc:oracle:thin:@127.0.0.1:1521:xsx"
maxActive="4"/>
</Context>
在conf文件夹下的server.xml文件中加个上面的内容.(加在<Server port="8005" shutdown="SHUTDOWN"></GlobalNamingResources>后面).
其中Resource name是数据源名称,在web.xml文件要有相应配置,如本例是:
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/CAAC</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
username和password是你ORACLE数据库的用户名和密码.
然后在ORACLE数据库中添加监听,在Net Configuration Assistant 进行配置. 主机名为127.0.0.1.