Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes How to create a java class(with/without main) to access websphere datasource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to create a java class(with/without main) to access websphere datasource" Watch "How to create a java class(with/without main) to access websphere datasource" New topic
Author

How to create a java class(with/without main) to access websphere datasource

Rashmi Birur
Greenhorn

Joined: Aug 29, 2001
Posts: 4
Hi,
I am using hit.db2.Db2Driver to access DB2. I have created a datsource by using websphere test environment of VAJ .
I am using the datasource in a bean class(java class without main()) and executing the query. code is here

java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
javax.naming.Context ctx = new javax.naming.InitialContext(parms);
ds = (javax.sql.DataSource)ctx.lookup("jdbc/hitDriver");
Conn = ds.getConnection(user, password);
Statement stmt = conn.createStatement()
lastResultSet = stmt.executeQuery(sqlcode);

When i access this bean from a servlet then it works but when i try to access it from a main() method of a simple java class it gives me this error:
Uncaught exception in evaluation: java.lang.NoClassDefFoundError: javax.naming.InitialContext
I was able to compile it successfully but when i do Run Main i get the above error.
Somebody ahd suggested to copy the ioser12.dll from websphere/appserver/jdk/jre/bin to WINNT/system.
But it didn't work.
Please let me know what i have to do regarding this.
Do i have to change the classpath ?
please reply
thanks
rashmi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to create a java class(with/without main) to access websphere datasource
 
Similar Threads
Initial Context problem
How to Bound JNDI names and references
exception when using WAS connection pool
Content.INITIAL_CONTEXT_FACTORY
How to create a java class(with main method) using the WebSphere DataSource