Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connect to Oracle with JNDI Environment Context

 
Leslie Smyth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic