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?