0
votes

I am working on an application that is configured on jdk 1.7

It uses JNDI to get connection with the Oracle DataSource.

I believe the JNDI name is not bound to server.

The line: DataSource ds = (DataSource) ServiceLocator.getinstance().getDataSource(jndiName); // jndiName = "jdbc/myDB"

looks for the JNDI name in 'cache' and if not found looks it up in 'initialContext'. But it gets null from both Maps.

The error that I am facing is: JNDI Name not found.

I have tried the following steps to solve this:

  1. Added < resource-ref > in the application web.xml file as below - < resource-ref > < description > MySQL Datasource example< / description > < res-ref-name > jdbc/myDB < /res-ref-name > < res-type>javax.sql.DataSource< /res-type > < res-auth>Container < /resource-ref >

  2. Added the < Resource > tag in server.xml file of the server as below - < Context > < Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource" maxActive="50" maxIdle="30" maxWait="10000" username="mysqluser" password="mysqlpassword" driverClassName=" oracle.jdbc.xa.client.OracleXADataSource " url="jdbc:mysql://localhost/myDB"/ > < / Context >

  3. Changed the first line mentioned above to: DataSource ds = (DataSource) ServiceLocator.getinstance().getDataSource("java:comp/env/jdbc/myDB");

  4. Added ojdbc14.jar to the server's lib folder

What should be the next approach to solve this?

1

1 Answers

1
votes

For (3) Do not use ojdbc14.jar, it is very old. Use ojdbc7.jar from the latest 12.1.0.2 version. You can download it from here.