Results 1 to 2 of 2

Thread: class cast exception while lookup

  1. #1
    Join Date
    Oct 2005
    Posts
    6

    Default 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. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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).
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 3
    Last Post: Sep 4th, 2005, 11:11 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •