通过 JNDI 调用 Oracle Application Server 的 OC4J 里面配置的Datasource , 

Tomcat 里面配置好的 app 移到 OC4J 里面用不了了, 查 Oracle 文档是发现如下描叙:

 

Portable Data Source Lookup

When the OC4J server starts, the data sources in the data-sources.xml file in the j2ee/home/config directory are added to the OC4J JNDI tree. When you look up a data source using JNDI, specify the JNDI lookup as follows:

DataSource ds = ic.lookup("jdbc/OracleCMTDS1");

The OC4J server looks in its own internal JNDI tree for this data source.

However, we recommend--and it is much more portable--for an application to look up a data source in the application JNDI tree, using the portable java:comp/env mechanism. Place an entry pointing to the data source in the application web.xml or ejb-jar.xml files, using the <resource-ref> tag. For example:

<resource-ref>
     <res-ref-name>jdbc/OracleDS</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
</resource-ref>

where <res-ref-name> can be one of the following:

  • The actual JNDI name--such as jdbc/OracleDS--that is defined in the data-sources.xml file. In this situation, no mapping is necessary. The preceding code example demonstrates this. The <res-ref-name> is the same as the JNDI name bound in the data-sources.xml file.

    Retrieve this data source without using java:comp/env, as shown by the following JNDI lookup:   

    InitialContext ic = new InitialContext();
    DataSource ds = ic.lookup("jdbc/OracleDS");