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:
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
posted
0
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