Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rashmi Birur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic