Announcement Announcement Module
Collapse
No announcement yet.
class cast exception while lookup Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • class cast exception while lookup

    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);
    }

  • #2
    Your problem is related to JBoss and not Spring; search the forums, IIRC there was a certain configuration parameter needed.
    Btw, you can use org.springframework.jndi.JndiObjectFactoryBean which can retrieve objects from JNDI (and use it inside your application context).

    Comment

    Working...
    X