cancel
Showing results for 
Search instead for 
Did you mean: 

Fetch jdbc connection factory via java:comp/env not working

Former Member
0 Kudos

I've created a JDBC data source with an alias, a/datasource. The alias shows up in the JNDI registry under /jdbc/a/datasource. In ejb-jar.xml, I have this:

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

Then, in ejb-j2ee-engine.xml, I have this:

<resource-ref>
     <res-ref-name>jdbc/DefaultResourceRef</res-ref-name>
     <res-link>jdbc/a/datasource</res-link>
</resource-ref>

Yet, when I execute this code:

ctx.lookup( "java:comp/env/jdbc/DefaultResourceRef");

I get an exception, with the core cause as follows::

Caused by: com.sap.engine.services.connector.exceptions.BaseResourceException: ConnectionFactory "jdbc/a/datasource" does not exist. Possible reasons: the connector in which ConnectionFactory "jdbc/a/datasource" is defined is not deployed or not started.

The JDBC connection is indeed functioning, and if I directly fetch jdbc/a/datasource, it works just fine.

What am I doing wrong?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Sometimes the datasource will go to not available state.you can start it using NWA. URL http://<nwserver>:50000/nwa

Slecect Configuration management>Infrastructure>application Resources.

Choose start and Stop Java EE Applications.

After opening this window search for your JDBC Connecter xml and choose start.

for example JDBCConnector_MYSQLDB_DS1.xml.

MYSQLDB_DS1 is my data source.

Sampath

Former Member
0 Kudos

Please re-read my question.

I'm looking for a solution that solves my 'java:comp/env' problem. As mentioned in my posting, I can access the JDBC connection factory using the direct name, but I want to use the abstracted java:comp/env path in my code.

Former Member
0 Kudos

Use the fallowing code.

DATASOURCENAME = "jdbc/MYSQLDB_DS1_ALIAS1"

ctx.lookup( DATASOURCENAME);

Go through this [blog|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/8675] [original link is broken] [original link is broken] [original link is broken];