【问题标题】:Migrate database connection from WAS to TOMCAT 7将数据库连接从 WAS 迁移到 TOMCAT 7
【发布时间】:2016-06-23 08:16:20
【问题描述】:

我的 WAS server.xml 中有一个这样的数据库连接:

<dataSource jdbcDriverRef="ORACLEDriver" jndiName="jdbc/jndiNameExample">
    <properties.oracle
        URL="*******"
        password="****" user="****" />
</dataSource>

<jdbcDriver id="ORACLEDriver" libraryRef="ORACLE" />

<library id="ORACLE">
    <fileset dir="C:\route1\route" includes="ojdbc6.jar" />
</library>

如何将此数据库连接迁移到 TOMCAT 7?

谢谢!

【问题讨论】:

    标签: tomcat datasource


    【解决方案1】:

    将ojdbc6.jar添加到tomcat lib目录。

    tomcat server.xml

    <Resource auth="Container" 
            driverClassName="oracle.jdbc.OracleDriver" 
            global="jdbc/jndiNameExample" 
            maxActive="100" 
            maxIdle="20" 
            maxWait="10000" 
            minIdle="5" 
            name="jdbc/jndiNameExample" 
            password="password" 
            type="javax.sql.DataSource" 
            url="jdbc:oracle:thin:@host:1521:ServiceName" 
            username="username"/>
    

    tomcat 上下文.xml

    <ResourceLink name="jdbc/jndiNameExample"
              global="jdbc/jndiNameExample"
              auth="Container"
              type="javax.sql.DataSource" />
    

    WEB-INF/web.xml

    <resource-ref>
    <description>Oracle Datasource</description>
    <res-ref-name>jdbc/jndiNameExample</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    

    连接代码

    Context ctx = new InitialContext(); 
    Context envContext = (Context) ctx.lookup("java:/comp/env"); 
    javax.sql.DataSource ds = (javax.sql.DataSource) envContext.lookup ("java:/comp/env/jdbc/jndiNameExample");
    

    【讨论】:

    • 谢谢!我是这样配置的,但它总是抛出这个异常: NameNotFoundException jndi name is no associated to this context。
    • 您是否将连接配置插入到 server.xml 中的&lt;GlobalNamingResources&gt;&lt;/GlobalNamingResources&gt; 中?
    • 是的,在 GlobalNamingResources 中。我需要在 web.xml 中插入一些东西吗?
    • 是的,还需要在WEB-INF/web.xml中插入如下配置&lt;resource-ref&gt; &lt;description&gt;Oracle Datasource&lt;/description&gt; &lt;res-ref-name&gt;jdbc/jndiNameExample&lt;/res-ref-name&gt; &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt; &lt;res-auth&gt;Container&lt;/res-auth&gt; &lt;/resource-ref&gt;
    • 我遇到了同样的异常(javax.naming.NameNotFoundException,在此上下文中未找到 jndi)
    猜你喜欢
    • 2019-04-29
    • 1970-01-01
    • 2013-06-05
    • 2017-06-09
    • 1970-01-01
    • 2016-08-18
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多