Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

connect to db2 using datasource problem

3 views
Skip to first unread message

teno

unread,
Oct 5, 2005, 4:54:19 AM10/5/05
to
hi all,

im trying to connect to db2 database using datasource and jndi using
the following code:

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,

"com.sun.jndi.cosnaming.CNCtxFactory");

env.put(Context.PROVIDER_URL,
"http://localhost:8888");

Context initialContext = new InitialContext(env);

Object o = initialContext.lookup("jdbc/sampleDS");

DataSource ds=(DataSource)o;
con=ds.getConnection();
stmt = con.createStatement();
rst = stmt.executeQuery("select MEGAILY.EMPLOYEE.LASTNAME from
MEGAILY.Employee where MEGAILY.EMPLOYEE.EMPNO='000010' ");

but i have the following exception when i try to run this code :

javax.naming.ConfigurationException: http://localhost:8888 does not
contain an IOR

at com.sun.jndi.cosnaming.CNCtx.getStringifiedIor(CNCtx.java:421)

at com.sun.jndi.cosnaming.CNCtx.initOrbAndRootContext(CNCtx.java:198)

at com.sun.jndi.cosnaming.CNCtx.<init>(CNCtx.java:69)

at
com.sun.jndi.cosnaming.CNCtxFactory.getInitialContext(CNCtxFactory.java:32)

at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)

at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)

at javax.naming.InitialContext.init(InitialContext.java:219)

at javax.naming.InitialContext.<init>(InitialContext.java:195)

at mypackage.Class2.main(Class2.java:72)

Process exited with exit code 0.


i dont know what is wrong please any one help me

thanks

rswartwood

unread,
Oct 5, 2005, 7:21:25 AM10/5/05
to
I'm not a developer but if your code is executing in a WebSphere
container, I don't believe you need to override the default Context
Factory or the provider URL. You might want to read the InfoCenter on
"Developing applications that use JNDI".

Also:
- you're using the wrong INITIAL_CONTEXT_FACTORY for a WebSphere
namespace. It should be
com.ibm.websphere.naming.WsnInitialContextFactory

-you're doing a direct lookup ("jdbc/sampleDS"). The recommendation is
to use an indirect lookup and a resource reference
("java:comp/jdbc/sampleDS");

- you're connecting to port 8888. That probably needs to be the
bootstrap port for an app server or node agent.

0 new messages