Hi This is my first discussion. Coming to the topic, I have created a Data Source (DB2) in WebSphere. JNDI name has been configured. I have done the Standalone application and got over. The question is how to LOOKUP JNDI name for the StandAlone application and how to ACCESS?
The program is as follows(code snippet):
class DBConnect4 {
public static void main(
String[] args) throws NamingException, SQLException {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
/*props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");*/
// --------------------the problem occurs here------------------------------------
// --------------------at props.put(Context.PROVIDER_URL,"iiop://............
props.put(Context.PROVIDER_URL, "iiop://172.23.99.88:9064");//172.23.99.88
System.out.println("The Connection is" + props);
try {
InitialContext initContext = new InitialContext(props);
Object obj = initContext.lookup("jdbc/myDataSource");
DataSource ds = (DataSource) obj;
Connection connection = ds.getConnection("db2admin", "123$");
System.out.println("Connection estblished");
I have configured everything, instead I am getting the following error:
The Connection is{java.naming.provider.url=iiop://172.23.99.88:9064, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory}
The Exception is:Failed to initialize the ORB
javax.naming.NamingException: Failed to initialize the ORB [Root exception is java.lang.ClassCastException: com.sun.corba.se.impl.orb.ORBImpl]
at com.ibm.ws.naming.util.Helpers.getOrb(Helpers.java:318)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:392)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:117)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:712)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:171)
at javax.naming.InitialContext.lookup(Unknown Source)
at src.DBConnect4.main(DBConnect4.java:27)
Caused by: java.lang.ClassCastException: com.sun.corba.se.impl.orb.ORBImpl
at com.ibm.ws.orb.GlobalORBFactory.init(GlobalORBFactory.java:86)
at com.ibm.ejs.oa.EJSORBImpl.initializeORB(EJSORBImpl.java:179)
at com.ibm.ejs.oa.EJSClientORBImpl.<init>(EJSClientORBImpl.java:83)
at com.ibm.ejs.oa.EJSClientORBImpl.<init>(EJSClientORBImpl.java:59)
at com.ibm.ejs.oa.EJSORB.init(EJSORB.java:102)
at com.ibm.ws.naming.util.Helpers.getOrb(Helpers.java:309)
... 6 more