cancel
Showing results for 
Search instead for 
Did you mean: 

JDBC connection error to DataSource

Former Member
0 Kudos

Hi,

I get the error 'Path to object does not exist at java:comp, the whole lookup name is java:comp/env/jdbc/UDF_Oracle_XIFunction' when I want to connect the DataSource.

This is the code in my java application:

InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/UDF_Oracle_XIFunction");
Connection con = ds.getConnection();

The DataSource alias name made in the JDBC Connector of the Visual Administrator is:

UDF_Oracle_XIFunction

I have a java and not a j2ee application. Is this the problem? But I need a jar-file because only jar- and zip.files are possible to upload into the imported archives for the message mappings in XI.

Have anybody an idea how to use the alias in the right way?

Thanx for help,

Susanne

Accepted Solutions (0)

Answers (1)

Answers (1)

Vlado
Advisor
Advisor
0 Kudos

Hi Susanne,

When you lookup a resource factory (what is a DataSource) from a non-J2EE component, you don't have the JNDI environment that J2EE components have.

This means you must not use the prefix <i>"java:comp/env"</i> but rather the path <i><b>"jdbc/client/<data-source-name>"</b></i>.

However, in this case you cannot use JTA transactions and there's no connection pooling, i.e. it's equivalent to calling DriverManager.getConnection(<connection-string>).

One more remark: if your application is not running on the server, you must provide the parameters when creating an InitialContext in the form:

Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
p.put(Context.PROVIDER_URL, "<host>:<port>");
p.put(Context.SECURITY_PRINCIPAL, "<user>");
p.put(Context.SECURITY_CREDENTIALS, "<password>");
InitialContext ctx = new InitialContext(p);

Hope that helps,

Vladimir