zoukankan      html  css  js  c++  java
  • Tomcat5.5x+jndi配置

    1、配置Tomcat5.5.X的Server.xml,在<host>下面加上: 

    <Context path="/JNDIDemo" docBase="D:\workspace\JNDIDemo\WebRoot" debug="0" reloadable="true" crossContext="true"
    <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_quality_log." suffix=".txt" timestamp="true"/> 
    <Resource 
    name="jdbc/test" <!-- JNDI数据池名称 --> 
    type="javax.sql.DataSource" <!-- 数据类 --> 
    password="karid" <!-- 密码 --> 
    driverClassName="oracle.jdbc.driver.OracleDriver" <!-- 驱动 --> 
    maxIdle="2" <!-- 最少可用lia --> 
    maxWait="5000" <!-- 最大等待时间 5秒 --> 
    username="karid" <!-- 用户名 --> 
    url="jdbc:oracle:thin:@127.0.0.1:1521:karid" 
    maxActive="4" <!-- 最大可用连接 --> /> 

    <ResourceParams name="jdbc/test"

    <parameter> 
    <name>removeAbandoned</name> 
    <!-- Abandoned DB connections are removed and recycled --> 
    <value>true</value> 
    </parameter> 
    <parameter> 
    <name>removeAbandonedTimeout</name> 
    <!-- Use the removeAbandonedTimeout parameter to set the number of seconds a DB connection has been idle before it is considered abandoned. --> 
    <value>60</value> 
    </parameter> 
    <parameter> 
    <name>logAbandoned</name> 
    <!-- Log a stack trace of the code which abandoned --> 
    <value>false</value> 
    </parameter> 

    <parameter> 
    <name>factory</name> 
    <!--DBCP Basic Datasource Factory --> 
    <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> 
    </parameter> 

    </ResourceParams> 



    2、配置web.xml

    <description>MySQL Test App</description> 
    <resource-ref
    <description>DB Connection</description> 
    <res-ref-name>jdbc/test</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
    </resource-ref

    3、JNDI使用

    public class DataSourceFactory 

    private static DataSource ds; 
    public static DataSource createDataSourde() 

    if (ds == null

    try 

    Context initContext = new InitialContext(); 
    if (initContext == null
    System.out.println("无配置环境"); 
    Context envContext = (Context) initContext.lookup("java:/compenv"); 
    ds = (DataSource) envContext.lookup("jdbc/test"); //根据名称取得数据源 

    catch (NamingException e) 

    e.printStackTrace(); 


    return ds; 

    }

  • 相关阅读:
    Jquery的小案例4、实现表单的验证(用户名和邮箱)
    Ubuntu下安装Python
    ListView列宽自适应
    IPtables 版本升级到 v1.4.9
    穿过已知点画平滑曲线(3次贝塞尔曲线)
    贪心算法——NY 14 会场安排问题
    零是奇数还是偶数?
    免费淘宝IP地址库简介及PHP/C#调用实例
    html锚点(mao dian)特殊的超链接
    怎么查看自己电脑的IP地址
  • 原文地址:https://www.cnblogs.com/alamps/p/2710545.html
Copyright © 2011-2022 走看看