打印本文 打印本文 关闭窗口 关闭窗口
在Tomcat 配置Oracle 及DB2中创建Connection Pool
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2653  更新时间:2009/4/22 22:03:53  文章录入:mintao  责任编辑:mintao
     <value>-1</value> 

            </parameter>

          </ResourceParams>

         

        </Context>

3.在相应用到该连接池的Web-app(部署好的web应用,一般在%TOMCAT_HOME%的webapps目录下,也可以通过编辑server.xml来改变,下同)的WEB-INF下面修改web.xm l,在web-app分支内加入数据源

<resource-ref>

            <description>Oracle Connectiong Pool</description>

            <res-ref-name>jdbc/oracle</res-ref-name>

            <res-type>javax.sql.DataSource</res-type>

            <res-auth>Container</res-auth>

  </resource-ref>

  <resource-ref>

            <description>Oracle Connectiong Pool</description>

            <res-ref-name>jdbc/DB2</res-ref-name>

            <res-type>javax.sql.DataSource</res-type>

            <res-auth>Container</res-auth>

  </resource-ref>  

测试及调用方法

<%

  Connection conn=null;

  Statement stmt =null;

  ResultSet rs=null;

   

  try{

              Context initContext = new InitialContext();

              Context envContext=(Context)initContext.lookup("java:/comp/env");

              DataSource ds = (DataSource)envContext.lookup("jdbc/DB2");

              conn = ds.getConnection();

              if(conn!=null){

                       System.out.println("create connection  sucess!");

                       stmt = conn.createStatement();

                       if(stmt!=null){

                                 System.out.println("create stmt sucess!");

                                  rs=stmt.executeQuery("select * from WST_TB_CITY");

                                 while(rs.next()){

                                            out.println(rs.getString("CITYNAME")+"<br>");

上一页  [1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口