aspose file tools
The moose likes Other Application Frameworks and the fly likes class cast exception while lookup  in spring Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Other Application Frameworks
Reply Bookmark "class cast exception while lookup  in spring" Watch "class cast exception while lookup  in spring" New topic
Author

class cast exception while lookup in spring

praveen kumar
Greenhorn

Joined: Sep 02, 2005
Posts: 4
HI,
Thanks in advance.please help me to solve this exception.
I am new to JBOSS and spring.I wrote a simple program which gets database connection from connection pool.In lookup I am getting class cast exception saying "Cannot cast javax.naming.Reference to javax.sql.DataSource-Class cast exception".I cannot understand how lookup returns a Reference object. The same thing works well in a JSP page.Here's my code:

public void dispCount() throws NamingException {

Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL,"jnp://localhost:1099");
Context ctx=new InitialContext(env);
DataSource ds = (DataSource) ctx.lookup("OracleDS");
JdbcTemplate jt = new JdbcTemplate(ds);
int count = jt.queryForInt("select count(*) from emp");
System.out.println("Count: "+count);
}
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 93
Class Cast Exceptions are the nightmare of JBoss. Make sure all your classpaths are correct and that you are using the correct libraries and there is no way for any confusion between jars (in particular j2ee.jar). Read more about the JBoss class loader woes on the net.

Eman
 
 
subject: class cast exception while lookup in spring
 
Threads others viewed
Websphere Connection Pooling
Datasource JNDI Lookup in WSAD from standalone app
JNDI lookup problem
mysql connectivity with jboss
JDBC lookup failure through java:comp....
IntelliJ Java IDE