6 Replies Latest reply on Apr 23, 2008 5:32 AM by jaikiran pai

    ClassCastException accessing a DataSource

    Andy Cooper Newbie

      Hi

      I know this as been discussed elsewhere loads of times and I have searched and searched and tried everything and still I get the same error. I'm sure its something simple but I just don't know enough to figure it out.

      I have a MySql database which I am trying to get the DataSource for using JNDI on a JBOSS 4.2.2 see all details below:

      JBoss 4.2.2
      MySQL 5.0
      Eclipse 3.3.2

      JNDI Properties

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=jnp://localhost:1099
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


      server/deploy/mysql-ds.xml

      <?xml version="1.0" encoding="UTF-8"?>

      <local-tx-datasource>
      <jndi-name>MySqlDS</jndi-name>
      <use-java-context>false</use-java-context>
      <connection-url>jdbc:mysql://localhost:3306/andy_test</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>user</user-name>
      pword
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>

      <type-mapping>mySQL</type-mapping>

      </local-tx-datasource>



      simple code

      import java.sql.*;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      public class DataSource {
      public static void main(String[] args) {
      InitialContext ic;
      try {

      InitialContext ic;
      DataSource ds =(DataSource)ic.lookup("MySqlDS");

      } catch (NamingException e) {
      e.printStackTrace();
      }
      catch (ClassCastException e){
      e.printStackTrace();
      }



      }
      }


      When I run this I get this error:

      java.lang.ClassCastException: $Proxy0
      at DataSource.main(DataSource.java:12)

      If anyone can advise me whether I'm doing something fundamentally wrong or a configuration error.

      Thanks