0
votes

I'm running Worklight 6.2, Oracle 11g, and Tomcat 7. If I hardcode the username/password in the adapter.xml, it works fine:

adapter.xml

<connectionPolicy xsi:type="sql:SQLConnectionPolicy">
    <dataSourceDefinition>          
        <driverClass>oracle.jdbc.OracleDriver</driverClass>
        <url>jdbc:oracle:thin:@d1chd1d3.xyz.com:1522/D1CHD</url>
        <user>MY_USER</user>
        <password>MY_PASS</password>
    </dataSourceDefinition>
 </connectionPolicy

However if I use a JNDI name in the adapter, it does not work on Tomcat 7.

adapter.xml

<connectionPolicy xsi:type="sql:SQLConnectionPolicy">
        <dataSourceJNDIName>jdbc/MyDatabase</dataSourceJNDIName>
</connectionPolicy>

When using the JNDI name in the adapter, I get the following error:

"Runtime: Datasource jdbc/MyDatabase not found in jndi"

I'm not sure if the backslash in the error message above is significant.

I ran the following command to display the JNDI entries Tomcat knows about and it seems to indicate the JNDI entry exists:

http://localhost:8080/manager/text/resources?type=javax.sql.DataSource

OK - Listed global resources of type javax.sql.DataSource
jdbc/MyDatabase :org.apache.tomcat.dbcp.dbcp.BasicDataSource

server.xml

 <Resource
          name="jdbc/MyDatabase"
          auth="Container"
          type="javax.sql.DataSource"
          driverClassName="oracle.jdbc.OracleDriver"
          url="jdbc:oracle:thin:@d1chd1d3.xyz.com:1522/D1CHD"
          username="MY_USER"
          password="MY_PASS"
          maxActive="20"
          maxIdle="10"
          maxWait="-1"/>

context.xml

<ResourceLink
name="jdbc/MyDatabase"
global="jdbc/MyDatabase"
type="javax.sql.DataSource" />

I am able to use a JNDI name when running the adapter, from Eclipse, using the built-in Liberty server. The problem only exists when running on Tomcat.

Any ideas why this is occurring? Is it possible to use a JNDI name from Tomcat 7 and connect to an Oracle 11g database?

1

1 Answers

0
votes

I'm being told that it is possible that the dataSourceJNDIName element in the connectionPolicy node in the adapter XML is configured incorrectly.

Try it with the following instead:

<connectionPolicy xsi:type="sql:SQLConnectionPolicy">
        <dataSourceJNDIName>java:comp/env/jdbc/MyDatabase</dataSourceJNDIName>
</connectionPolicy>