ClassCastException : javax.naming.Reference JNDI Datasource
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nitin_H
Posted On:   Monday, November 17, 2003 04:27 PM

Env : WSAD 5.1 DB2 v7 Server : WTE v5 (bulitin WSAD5.1) DataSource : myDS jndi name : jdbc/myDS Server started : name server port : 2809 // standalone java program code ------------- try{ Properties prop = new Properties(); prop.put(INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory"); props.put(Context.PROVIDER_URL,"iiop://localhost:2809"); InitialContext ctx = new InitialContext(props); DataSource ds = (DataSource) ctx.lookup("jdbc/myDS"); /*tried DataSource ds = javax.rmi.Portable   More>>

Env :

WSAD 5.1

DB2 v7



Server : WTE v5 (bulitin WSAD5.1)

DataSource : myDS

jndi name : jdbc/myDS



Server started : name server port : 2809



// standalone java program code -------------



try{

Properties prop = new Properties();

prop.put(INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");

props.put(Context.PROVIDER_URL,"iiop://localhost:2809");

InitialContext ctx = new InitialContext(props);

DataSource ds = (DataSource) ctx.lookup("jdbc/myDS");



/*tried DataSource ds = javax.rmi.PortableRemoteObject.narrow( (new InitialContext(props)).lookup("jdbc/TrainDS"),
javajavax.sql.DataSource.class); */




}catch(Exception e){

System.out.println(e); }



output :



ClassCastException : javax.naming.Reference



changed code to



Object ds = ctx.lookup("jdbc/myDS");

System.out.println(ds.getClass());


prints 'javax.naming.Reference'




An object is being returned, but not of type DataSource. I have no clue what type the object is refering to.



Any clues ?? Am I facing compatibility issues with DB2 v7 ?


Any idea?




Thanks. nitiN.

   <<Less

Re: ClassCastException : javax.naming.Reference JNDI Datasource

Posted By:   Nitin_H  
Posted On:   Tuesday, December 2, 2003 04:59 PM





Solution :



1. Make sure the programming JRE is the same as the server JRE that your program will run on



WSAD ->Windows -> Preferences -> Java -> Installed JREs . typically websphere v5 JRE.




2. Make sure you have these libraries in your application classpath



cmImpl.jar

j2cImpl.jar

j2ee.jar

jmxx.jar

naming.jar

namingclient.jar

namingserver.jar

securityImpl.jar

txPrivate.jar

webContainer.jar

JRE system library (variable)

WAS_V5_IMPL_FACTORY_PROP (predefined folder)







some of the above libraries may not be necessary, but I did not investigate further. Those are the libraries currently being used by my program.




-Nitin (self- answered) ;)
About | Sitemap | Contact