Google Analytics

 

Wednesday, January 23, 2008

Call Data Source [Websphere] From Java Application

It's 2 Way to Call

1. Use Library From Websphere [Use Rad to Call]

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere .naming.WsnInitialContextFactory"); // Context Name For Call
env.put(Context.PROVIDER_URL, "iiop://localhost:2809/");// IP Address of JNDI Name which you can look at Servers --> Application Server and then Server that use JDBC --> Port (Communications) --> BOOTSTRAP_ADDRESS
InitialContext ctx = new InitialContext(env);
DataSource ds = (DataSource) ctx.lookup("jdbc/test");//JNDI Name
PS. You must add Websphere 6.0 Library and JRE [in Websphere]

2. Use Context Sun [But I tested, It still return NULL.]
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi .cosnaming.CNCtxFactory"); // Sun Context
env.put(Context.PROVIDER_URL, "iiop://localhost:2809/");// IP Address of JNDI Name which you can look at Servers --> Application Server and then Server that use JDBC --> Port (Communications) --> BOOTSTRAP_ADDRESS
InitialContext ctx = new InitialContext(env);
DataSource ds = (DataSource) ctx.lookup("cell/nodes/Node01/servers/server1/jdbc/test"); //JNDI Name [You call Real Path] --> cell/nodes/< node Name > /servers/< server Name >