• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

InitialContext(): setting envirnment variables with a Hashtable

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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() {
}
}
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Valentin. I will have to see how WebSphere handles data sources.
 
Dinner will be steamed monkey heads with a side of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic