Tomcat5 DataSource的配置和测试

Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to $CATALINA_HOME/conf/server.xml.

Add this in between the </Context> tag of the examples context and the </Host> tag closing the localhost definition 

 <Context path="/wfms" docBase="wfms" debug= "99" reloadable="true" crossContext="true">
          <Resource name="jdbc/epmp"  type="javax.sql.DataSource" auth="Container"/>
          <ResourceParams name="jdbc/epmp">
           <parameter>
            <name>username</name>
            <value>demo4bt</value>
            </parameter>
            <parameter>
            <name>password</name>
            <value>demo4bt</value>
            </parameter>
            <parameter>
            <name>driverClassName</name>
              <value>oracle.jdbc.driver.OracleDriver</value>
            </parameter>
            <parameter>
            <name>url</name>
              <value>jdbc:oracle:thin:@192.168.33.244:1522:db10gr2</value>
              </parameter>
          </ResourceParams>
        </Context>

一般在web.xml中还要加入如下代码:

<resource-ref>
 <res-ref-name>jdbc/epmp</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
 <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

然后写程序测试,

Context initCtx = new InitialContext();

 DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/epmp");

 conn = ds.getConnection();

一般这个就ok了,可是我的测试没有通过提示错误:关于 "com.sun.jndi.fscontext.RefFSContextFactory"

在jre lib中jndi下找了找,没有发现,网上搜索了一番,原来还有一个fscontext.jar 还要自己下载引

入。为什么在JRE System Lib的com.sun.jndi.下没有呢,看来要问Sun了?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值