All friends:
    hello.
    I had used DataSource accompanyed with tomcat5.I configured this Data which named 
"JDBC/ORADB" via the web page "http://localhost:8080/admin",everything was 
completed.then ,i retrieved this DataSource on my client which is an application.
My core code of client is here:

  java.util.Properties p = new java.util.Properties();
  p.put( Context.INITIAL_CONTEXT_FACTORY,"org.apache.naming.factory.ResourceFactory");
  //p.put( 
Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
  p.put( Context.PROVIDER_URL,"http://localhost:8080";);
  //  System.setProperty("java.naming.factory,initial", 
"org.apache.catalina.users.MemoryUser");  
  try {
   Context context = new javax.naming.InitialContext( p);
   Context initCtx = ( Context)context.lookup("java:comp/env");
   DataSource ds = ( DataSource) initCtx.lookup("JDBC/ORADB");
   return ds;
  } catch (NamingException e) {
   e.printStackTrace();
   return null;
  }

but it failed.And the all err message like this :
javax.naming.NoInitialContextException: Cannot instantiate class: 
org.apache.naming.factory.ResourceFactory.  Root exception is 
java.lang.ClassCastException
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
 at javax.naming.InitialContext.init(InitialContext.java:219)
 at javax.naming.InitialContext.<init>(InitialContext.java:195)
 at com.airversal.cer.utility.service.ServiceImp.getDataSource(ServiceImp.java:48)
 at com.ariversal.cer.debug.DSTest.main(DSTest.java:21)

i do not know what had happend.i look view some sample code on www.apache.org. They 
all are too simple.Error occur with my try.

what had happend or how did i use datasource with tomcat5,i beg someone give me some 
introduce and some advise .

Reply via email to