Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Posts: 4
  • Mark post as helpful
  • send pies
  • 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
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!