aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes WSAD accessing datasource via standalone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "WSAD accessing datasource via standalone" Watch "WSAD accessing datasource via standalone" New topic
Author

WSAD accessing datasource via standalone

Sunil Dumpala
Greenhorn

Joined: Jul 28, 2005
Posts: 29
I coded a simple HelloWorld program by creating a java project in WSAD. I added a datasource in my Test Server in WSAD. All I was trying to do was access the datasource using JNDI. Standard way of soing it (if it were a jsp or any J2EE application ) would be as follows

javax.naming.InitialContext ctx = new javax.naming.InitialContext();
DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/UASSUNILLOCALds");

For some reason Server was trying to read WEB-INF/config/server.properties file and was throwing a FileNotFoundException. I found a similar posting on the net where someone suggested to change the code as follows

1. Hashtable env = new Hashtable();
2.env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
3. javax.naming.InitialContext ctx = new javax.naming.InitialContext();
4. DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/UASSUNILLOCALds");

And included whole bunch of jar files such as naming.jar, namingclient.jar, wssec.jar, lmproxy.jar, sas.jar, implfactory.jar, ecutils.jar and a implproperties.properties file into the classpath.Now I am able to get the context but I am getting ClassCastException on line 4. The reason is ctx.lookup is returning me the javax.naming.Reference object of DataSource "jdbc/UASSUNILLOCALds". I am using JDK 1.3 and included the classes12.jar oracle driver files.

I need to create a standalone java file which would be run as batch job. If I can access the datasource through JNDI then I could have placed the file as part of bigger application and use the server connection pools etc., But since this didn't work out and I am running out of time, I am planning to use iBatis. If anybody has any suggestions on how to get the issue rectified or any comments on the usage of iBATIS please let me know. I am new to iBTAIS too so not sure if that would work out or not.

Thanks,
Sunil
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: WSAD accessing datasource via standalone
 
Similar Threads
Oracle Datasource V5 error in Websphere 5.1.2
Access Server's Datasource from standalone
WAS 6.1 JDBC problem
Oracle Datasource V5 error in Websphere 5.1.2
How to Bound JNDI names and references