This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Oracle JDBC connection using JNDI lookup
 
Similar Threads
Small JDBC application.
jdbc 2.0 connection pooling
Connection Pool and Data Source
Obtain reference of database connection pool within EJB stateless bean for OC4J
Problem in getting connection from data source