This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

InitialContext(): setting envirnment variables with a Hashtable

 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an old problem with a new twist. I am trying to do a jndi lookup on an entity bean that is using an Oracle data source.

Since WebSphere server cannot locate an Oracle database by default, I assume I need to pass the WAS Context the url and maybe a context factory name of some sort.

I don't have the values set correctly, and I cannot find any WAS-Oracle examples using a Hashtable to pass environment variables.

Would you take a look at my two put statements for my Hashtable (env)?



package sessions;

import java.util.Hashtable;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.*;

import entities.ora9EmpLocal;
import entities.ora9EmpLocalHome;
/**
* Bean implementation class for Enterprise Bean: Session1
*/
public class Session1Bean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;
/**
* getSessionContext
*/
static final String jndiName = "ejb/entities/ora9EmpLocalHome";

public void runOra9Emp(int empno){
ora9EmpLocalHome oh;
ora9EmpLocal ol;

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "oracle.jdbc.driver.OracleDriver");
env.put(Context.PROVIDER_URL, "jdbc racle:thin:@AVALON:1521:JINXSID");

try {
InitialContext initialContext = new InitialContext(env);
Object homeObject = initialContext.lookup(jndiName);
oh = (ora9EmpLocalHome) homeObject;


} catch (NamingException e) {

e.printStackTrace();
}




}


public javax.ejb.SessionContext getSessionContext() {
return mySessionCtx;
}
/**
* setSessionContext
*/
public void setSessionContext(javax.ejb.SessionContext ctx) {
mySessionCtx = ctx;
}
/**
* ejbCreate
*/
public void ejbCreate() throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() {
}
}
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Burke,

In my opinion there is a different approach for the container to "locate" a database. Usually your container allows defining connection pools and data sources for accessing connections from the pool. At start time the container will bind the data source to the jndi allowing applications to look up the data source. Here there is an extract from a config.xml (used with WebLogic, sorry...) that defines a data source that binds to jndi tree under the MYDATA name

Usually the container will provide you tools for setting data sources in a very friendly manner.
Here there is a piece of server code that gets a connection using MYDATA data source:

Regards.
 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Valentin. I will have to see how WebSphere handles data sources.
 
Your mind is under my control .... your will is now mine .... read this tiny ad
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!