Skip to Content
author's profile photo Former Member
Former Member

Datasource Lookup from Server component

Hi,

I know the issue has been risen a couple of times here, but I was not able to find the solution for me. I cannot retrieve my datasource for my server component. I am a not to sure about some configuration details:

<b>1. Visual Admistrator - JDBC Connector configuration</b>

How does the application name affect the lookup operation of the DS in JNDI. Or is it simply a name to group datasources?

<b>2. Configuration of the DataSource</b>

I have a DS with the name direct_jdbc and an alias myApp/jdbc/datasources/direct_jdbc. I can see the datasource in the JNDI Registry at multiply nodes.

+ root/jdbc/direct_jdbc

+ root/jdbc/myApp/jdbc/datasources/direct_jdbc

+ root/jdbc/notx/direct_jdbc

+ root/jdbc/notx/myApp/jdbc/datasources/direct_jdbc

+ root/jdbc/client/jdbc/direct_jdbc

+ root/jdbc/client/jdbc/myApp/jdbc/datasources/direct_jdbc

Why are the "notx" and "client" nodes containing DS references? Which one do I need to lookup?

I have defined the following <db-properties> in my persistent.xml files:

<db-properties>
  <data-source-name>
    myApp/jdbc/datasources/direct_jdbc
  </data-source-name>
</db-properties>

My client lookup is as follows:

InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/myApp/jdbc/datasources/direct_jdbc");
Connection con = ds.getConnection();

The lookup results in the following Exception

com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException:
Object not found in lookup of myApp/jdbc/datasources/direct_jdbc.

I really don't see why this is not working. The datasource is defined and the JNDI-path looks ok to me. Why does the lookup fail?

Any answers are highly appreciated.

best regards

Marcel

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Nov 24, 2005 at 04:30 PM

    Hi Marcel,

    You say, you define the DataSource in a

    persistent.xml

    which is defined only for CMP Entity EJBs.

    I have a feeling, you look up the so defined DataSource from another component like a servlet. Than you would have to set a reference from the web application to the bean and the lookup would work over the local JNDI reference (something like

    java:comp/env/jdbc/<DS_Name>

    ... check the specification!)

    I do not think you are looking the DataSource up from a remote client, since the InitialContext would have to be obtained with properties (you would also get a different exception) - beyond the fact, that looking a DataSource from a remote client is forbidden (as far as I know - I might be wrong here).

    Other than that, both lookups:

    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("jdbc/direct_jdbc");
    Connection con = ds.getConnection();

    as well as

    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("jdbc/myApp/jdbc/datasources/direct_jdbc");
    Connection con = ds.getConnection();

    should actually work. Hmm ... are you sure about the "right" JNDI context?

    Cheers, Goran

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.