Tomcat 6 数据源配置

I.

 

%Tomcat_Home%\conf\ 下面的context.xml 在<Context>中加入下面的代码

 

<Resource name="jdbc/oracle" auth="Container" type="javax.sql.DataSource" maxActive="10" maxIdle="10" maxWait="1000" username="scott" password="tiger" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:ORCL"/>

 

 

II.

 

编辑项目下的web.xml文件,在<web-app>中加入下面的代码

 

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

 

III.

 

建一个servlet测试一下:

 

 Connection conn = null;
   try
    {
        Context initContext = new InitialContext();
        Context envContext = (Context)initContext.lookup("java:/comp/env");
        DataSource ds = (DataSource)envContext.lookup("jdbc/oracle");
        conn = ds.getConnection();
   if(conn != null)
   {  out.println("Tomcat数据源连接成功!");  }
 }
 catch(Exception e)
 {
   e.printStackTrace();
 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值