GeeCON Prague 2014*
The moose likes Websphere and the fly likes RAD6 datasource access using JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Websphere
Bookmark "RAD6 datasource access using JNDI" Watch "RAD6 datasource access using JNDI" New topic
Author

RAD6 datasource access using JNDI

Harikrishna kishore Harkala
Greenhorn

Joined: Mar 31, 2008
Posts: 3
When Iam writing code like given below for datasource access using JNDI

public class DataSourceJNDI {

public static void main(String[] args)throws SQLException,NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext ctx = new InitialContext(env);
DataSource ds = (DataSource) ctx.lookup("jdbc/CMPDS");
Connection con=ds.getConnection();
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT NAME,ID,DEPT FROM EMPLOY");
String name=rs.getString("NAME");
String id=rs.getString("ID");
String dept=rs.getString("DEPT");
System.out.println(name);
System.out.println(dept);
System.out.println(id);

}
}
I am getting aruntime exception like this:
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory. Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:375)
at java.lang.ClassLoader.loadClass(ClassLoader.java:562)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:442)
at java.lang.ClassLoader.loadClass(ClassLoader.java:494)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:60)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:257)
at javax.naming.InitialContext.init(InitialContext.java:233)
at javax.naming.InitialContext.<init>(InitialContext.java:209)
at Ray.DataSourceJNDI.main(DataSourceJNDI.java:25)

Please any one can help me?
sudheer babu
Greenhorn

Joined: May 29, 2008
Posts: 6
Originally posted by Harikrishna kishore Harkala:
When Iam writing code like given below for datasource access using JNDI

public class DataSourceJNDI {

public static void main(String[] args)throws SQLException,NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext ctx = new InitialContext(env);
DataSource ds = (DataSource) ctx.lookup("jdbc/CMPDS");
Connection con=ds.getConnection();
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT NAME,ID,DEPT FROM EMPLOY");
String name=rs.getString("NAME");
String id=rs.getString("ID");
String dept=rs.getString("DEPT");
System.out.println(name);
System.out.println(dept);
System.out.println(id);

}
}
I am getting aruntime exception like this:
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.websphere.naming.WsnInitialContextFactory. Root exception is java.lang.ClassNotFoundException: com.ibm.websphere.naming.WsnInitialContextFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:375)
at java.lang.ClassLoader.loadClass(ClassLoader.java:562)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:442)
at java.lang.ClassLoader.loadClass(ClassLoader.java:494)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:60)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:257)
at javax.naming.InitialContext.init(InitialContext.java:233)
at javax.naming.InitialContext.<init>(InitialContext.java:209)
at Ray.DataSourceJNDI.main(DataSourceJNDI.java:25)

Please any one can help me?
sudheer babu
Greenhorn

Joined: May 29, 2008
Posts: 6
hi,
did you check whether the class name you have given for the intial context is the same as you have provided. also check whether that class file is provided in the class directory.
if all these are correct, then better check for the web.xml file for the context variable.
hope you will find the solution in one of these...
 
GeeCON Prague 2014
 
subject: RAD6 datasource access using JNDI