How to lookup JNDI resources on WebLogic?

You should be able to simply do this: Context context = new InitialContext(); dataSource = (javax.sql. DataSource) context. Lookup("jdbc/myDataSource"); If you are looking it up from a remote destination you need to use the WL initial context factory like this: Hashtable h = new Hashtable(7); h.

Put(Context. INITIAL_CONTEXT_FACTORY, "weblogic.jndi. WLInitialContextFactory"); h.

Put(Context. PROVIDER_URL, pURL); h. Put(Context.

SECURITY_PRINCIPAL, pUsername); h. Put(Context. SECURITY_CREDENTIALS, pPassword); InitialContext context = new InitialContext(h); dataSource = (javax.sql.

DataSource) context. Lookup("jdbc/myDataSource").

– wsb3383 Jun 28 at 22:59 No. You mention in your post that the JNDI name is "jdbc/myDataSource". If the JNDI name is "I.Am.Jeff.

West" then you would do dataSource = (javax.sql. DataSource) context. Lookup("I.Am.Jeff.

West"). However, I personally like to organize things with a prefix that makes the JNDI tree cleaner.By the way, you never responded to my request to ask about you migrating from JBoss to WebLogic - jeffrey. West@oracle.

Com :) – Jeff West Jun 28 at 23:55 Actually, I suppose the answer to your question could be 'yes'. Either way, when you use the WebLogic Initial Context Factory you specify the full JNDI name with no other prefix. – Jeff West Jun 30 at 22:03.

Java is the root JNDI namespace for resources. What the original snippet of code means is that the container the application was initially deployed in did not apply any additional namespaces to the JNDI context you retrieved (as an example, Tomcat automatically adds all resources to the namespace comp/env, so you would have to do dataSource = (javax.sql. DataSource) context.

Lookup("java:comp/env/jdbc/myDataSource"); if the resource reference name is jdbc/myDataSource). To avoid having to change your legacy code I think if you register the datasource with the name myDataSource (remove the jdbc/) you should be fine. Let me know if that works.

Thanks for the answer. I tried doing that, but i'm still getting the same error. I'm not sure if there's some configuration issue with the WebLogic server itself.

– wsb3383 Jun 28 at 17:15 Can you show your WebLogic resource definition (minus passwords/hostnames and such)? Also, I'm assuming you can't (or would rather not) recompile the code? – Femi Jun 28 at 17:37 Are you talking about the weblogic.

Xml? I don't have any. I only have Web-based admin console access to the server.

I defined a generic data source and entered myDataSource for a JNDI name. – wsb3383 Jun 28 at 18:01 Ah, interesting: you might be able to add a resource ref for the specific legacy application that would correct the error, so I'd play with that interface. However you may still need to recompile your source if you can't quite get it to work.

What J2EE server was the application deployed on originally? – Femi Jun 28 at 19:50 thanks I'll try that. It was originally deployed on JBoss with datasource xml files.

– wsb3383 Jun 28 at 21:16.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions