3 Replies Latest reply on Aug 30, 2006 1:24 PM by Peter Johnson

    Class Cast Exception thrown when casting Data Source jboss

    Pranavakumar karuppiah Newbie

      HI
      I am trying to get a DataSource object in a stand alone java program.
      this is my program

      import java.util.*;
      import javax.naming.*;
      public class jndi {
       public static void main(String args[]){
       try{
      
       Properties prop = new Properties();
       prop.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       prop.put("java.naming.provider.url","jnp://localhost:51099" );
       prop.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
       Context context = new InitialContext(prop);
       Object dSource = context.lookup("java://qpmDS");
       System.out.println(dSource.toString());
       javax.sql.DataSource da =(javax.sql.DataSource) dSource;
      
       }catch(Exception ex){
       ex.printStackTrace();
       System.out.println("Error-1.0"+ex);
       }
      
       }
      }
      
      

      Here
      Object dSource = context.lookup("java://DSname");
      

      dSource object is a org.jnp.interfaces.NamingContext's object
      When i try to type cast it it throwing Type cast exception
      pls let me is there any problem in my code.


      Pranav