aspose file tools*
The moose likes BEA/Weblogic and the fly likes Oracle JDBC connection using JNDI lookup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "Oracle JDBC connection using JNDI lookup" Watch "Oracle JDBC connection using JNDI lookup" New topic
Author

Oracle JDBC connection using JNDI lookup

Lars Ulrich
Greenhorn

Joined: Dec 03, 2002
Posts: 3
I want to connect to an Oracle database using a servlet. I have set up the Connection Pool and Data Source in Weblogic. How do I write code for a JNDI lookup to access the Connection Pool and Data Source that I set up?
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
See the BEA documentation here: Using DataSources.
meital ben
Greenhorn

Joined: Jun 05, 2002
Posts: 12
Hi.
If you are using a DataSource :
// Obtain a Datasource connection from the WebLogic JNDI tree.
Context ctx = null;

// Put connection properties in to a hashtable.
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
// Get a context for the JNDI look up
ctx = new InitialContext(ht);
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("put here your DataSource JNDI Name");
conn = ds.getConnection();
....
[ December 03, 2002: Message edited by: meital ben ]

Meital
Simon Kelly
Greenhorn

Joined: Oct 02, 2002
Posts: 11
How do you bind the database connection to the JNDI Lookup. What xml dd files are you required to edit and what entries do you make? Is there any documentation provided by WL for these questions - apart from instructions on how to use their Management Console?
Thanks in advance...
 
 
subject: Oracle JDBC connection using JNDI lookup