5 Replies Latest reply on May 8, 2003 1:43 PM by shelly

    JBoss 3.2 and MySQL - Could not dereference DataSource objec

    Tom Marrs Newbie

      I get the following exception:

      javax.naming.NamingException: Could not dereference object [Root exception is java.lang.NullPointerException]

      when I try to connect to a DataSource with the following code (this is from a Servlet):

      Context ctx = new InitialContext();
      DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/JackalopeDB");
      conn = ds.getConnection();

      JBoss deploys the MBean for the database properly.

      JBoss Version: jboss-3.2.0_tomcat-4.1.24
      Database Server: MySQL v. 4.0.12
      Database Driver: mysql-connector-java-3.1.0-alpha

      I don't use jboss.xml or jboss-web.xml

      Here's the relevant portion of web.xml:
      Jackalope DB Connection

      I copied the Driver's Jar file to %JBOSS_DIST%/server/default/lib to make sure it was on the JBoss CLASSPATH.

      I copied %JBOSS_DIST%/docs/examples/jca/mysql-ds.xml to %JBOSS_DIST%/server/default/deploy and modified it to look like:


      I also had the same NullPointerException when I used MySQL Server v. 3.23.52 and MySQL Driver Version 2.0.14.

      I don't think the problem is with the version of MySQL.
      I must've configured things incorrectly.

      What am I doing wrong?

      Did I copy the driver to the right directory?
      Does mysql-ds.xml look OK?
      Is there another XML file that I need to modify. If so, which one and how?

        • 1. Re: JBoss 3.2 and MySQL - Could not dereference DataSource o
          David Jencks Master

          I'm not familiar with web configuration. I think you need an additional jboss specific file to map the java:/comp/env/jdbc/JackalopeDB to a non-private jndi entry, such as java:/jdbc/JackalopeDB where your datasource should be deployed. Alternatively you could simply look up java:/jdbc/JackalopeDB directly

          • 2. Re: JBoss 3.2 and MySQL - Could not dereference DataSource o
            anupj Newbie

            I am also facing the same problem, if u got a solution, please mail it to me also



            • 3. Re: JBoss 3.2 and MySQL - Could not dereference DataSource o
              Tom Marrs Newbie

              I don't think this has anything to do with the web because <resource-ref> in web.xml is the same as in ejb-jar.xml

              I don't think this is a JNDI issue because I'm able to access EJBs from my Servlet, and I was able to use ENC-style naming conventions ("java:comp/env/ejb/Hello") to lookup the "Hello" EJB.
              Since I can do this with EJB's, then I should be able to access a DataSource with java:comp/env/jdbc/JackalopeDB"

              I don't think the sample mysql-ds.xml (from docs/examples/jca) has everything it needs OR there's another step in login-config.xml that I'm missing. It doesn't look like JBoss is loading the MySQL driver (at least according to the server log).

              Does anyone have a working example that could share?


              • 4. Re: JBoss 3.2 and MySQL - Could not dereference DataSource o
                Dana Dudley Newbie

                Was a solution ever found for this? I am having the same problem and it's driving me nuts. My datasource connection is retrieved in some cases and not others and it's really baffling.

                • 5. Re: JBoss 3.2 and MySQL - Could not dereference DataSource o
                  shelly Newbie


                  i'm also having almost similar problem. I'm trying to configure mysql4.0.12 in jboss-3.2.1_tomcat-4.1.24.

                  I created a mysql-service.xml and put it in jboss-dist/server/default/deploy and put mysql-connector-java-3.0.7-stable-bin.jar in jboss-dist/lib.

                  mysql-service.xml looks like this:

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

                  ConnectionURL=jdbc:mysql://localhost:3306/test DriverClass=org.gjt.mm.mysql.Driver UserName=shelly Password=nebula
                  <depends optional-attribute-name="ResourceAdapterName">jboss.jca:service=RARDeployment,name=Minerva JDBC LocalTransaction ResourceAdapter
                  <depends optional-attribute-name="ConnectionManagerFactoryLoaderName">jboss.jca:service=ConnectionManagerFactoryLoader,name=MinervaSharedLocalCMFactory
                  BlockingTimeoutMillis=500000 IdleTimeoutMinutes=30 MaxSize=10 CleanupIntervalMinutes=10 MinSize=0 MaxIdleTimeoutPercent=1.0

                  i get the following errors while deployment:

                  org.jboss.deployment.DeploymentException: create operation failed for package file:/C:/jboss-3.2.1_tomcat-4.1.24/server/default/deploy/mysql-service.xml; - nested throwable: (javax.management.InstanceNotFoundException: jboss.jca:service=ConnectionFactoryLoader,name=mySqlDS is not registered.)

                  Does somebody know what else needs to be done.