aspose file tools*
The moose likes JDBC and the fly likes Connect to Oracle with JNDI Environment Context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connect to Oracle with JNDI Environment Context " Watch "Connect to Oracle with JNDI Environment Context " New topic
Author

Connect to Oracle with JNDI Environment Context

Leslie Smyth
Greenhorn

Joined: Dec 17, 2009
Posts: 2
Using Weblogic 10, Oracle 10, and java jdk 1.6 -
attempting to obtain a java code connection to Oracle database
using the named JNDI datasource.

Have created a DataSource, "MY_DataSource" with associated
JNDI name ""MY_DataSource".

Went to View JNDI Tree and could see the MY_DataSource name
listed right above the weblogic attribute.

Went to Monitoring tab for MY_DataSource, checked the AdminServer
upon which MY_DataSource is running, and pressed the TestDataSource
button; the message returned was that the test was successful.

Am unable to obtain a non-null connection value in my java code
using the JNDI name with environment and context variables.
Code is below:

weblogic.jndi.Environment env = new Environment();
javax.naming.Context context = env.getInitialContext();

javax.sql.DataSource dataSource = (DataSource)context.lookup(MY_DataSource);

java.swl.Connection connect = dataSource.getConnection();

In Debug mode, the context structure has a value of null for the env variable.

Would appreciate help in solving this problem.
Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
This link explains how to in weblogic under section Obtaining a Client Connection Using a DataSource. You may find it useful.

Regards,

Fatih.
Leslie Smyth
Greenhorn

Joined: Dec 17, 2009
Posts: 2
Thanks for the reference.

Have read this documentation before. Did check the honor global transactions.
Believe that I am already doing what is in the documentation, but am obviously
missing something. Am using a thin Oracle Driver - does this make a difference?
Some of the code example create an Environment object and then create a context
from that - see initial posting. See some code example that create a hashtable
object and then they set Initial_Context_factory and Provider_URL properties.
Have tried both ways - neither appears to work - which one is preferred?
What would be the provider_URL - t3://localhost:7001 for weblogic running on
local machine?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connect to Oracle with JNDI Environment Context