aspose file tools*
The moose likes JDBC and the fly likes How to create a java class(with main method) using the WebSphere DataSource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to create a java class(with main method) using the WebSphere DataSource " Watch "How to create a java class(with main method) using the WebSphere DataSource " New topic
Author

How to create a java class(with main method) using the 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
<code>
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);
</code>
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create a java class(with main method) using the WebSphere DataSource
 
Similar Threads
How to Bound JNDI names and references
Cannot find method compilation error
Content.INITIAL_CONTEXT_FACTORY
exception when using WAS connection pool
How to create a java class(with/without main) to access websphere datasource