• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
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
    Bookmark Topic Watch Topic
  • New Topic