6 Replies Latest reply on Aug 15, 2002 1:17 PM by Tony Dulin

    Problems Connecting to mysql

    Alan Bryson Newbie

      Problem Connecting to Mysql

      I am using the jboss-3.0.0_tomcat-4.0.3 configuration with mysql on
      a Windows 2000 machine. I am having problems connecting to mysql with an error of
      no resource manager found for MySqlDS.

      I have removed the hsqldb-service.xml from the deploy directory replacing it with a
      mysql-service.xml.

      see attached file

      I have also edited the login-config.xml file adding

      <!-- Security domains for testing new jca framework -->
      <application-policy name = "MySqlDbRealm">

      <login-module code=
      "org.jboss.resource.security.ConfiguredIdentityLoginModule"
      flag = "required">
      <module-option name = "principal">developer</module-option>
      <module-option name = "userName">alan</module-option>
      <module-option name = "password"></module-option>
      <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MySqlDS</module-option>
      </login-module>

      </application-policy>

      And the standardjaws.xml changing the DefaultDS to


      java:/MySqlDS
      <type-mapping>MySql SQL</type-mapping>
      false

      And also the standardjbosscmp.xml again changing ther DefaultDS to


      java:/MySqlDS
      <datasource-mapping>Mysql SQL</datasource-mapping>

      My ejb code is


      System.out.println("Start5");
      Context ic2 = new InitialContext();
      System.out.println("Start6");
      //DataSource ds = (DataSource) ic2.lookup("java:comp/env/MySqlDS");
      DataSource ds = (DataSource) ic2.lookup("java:MySqlDS");
      System.out.println("Start7");
      conn = ds.getConnection();


      This errors on the DataSource ds = (DataSource) ic2.lookup("java:MySqlDS") line


      javax.naming.NameNotFoundException: DefaultDS not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:509)


      2002-08-12 17:51:44,077 INFO [STDOUT] Start5
      2002-08-12 17:51:44,077 INFO [STDOUT] Start6
      2002-08-12 17:51:44,077 ERROR [STDERR] FATAL!
      2002-08-12 17:51:44,087 ERROR [STDERR] Exception:MySqlDS not bound
      2002-08-12 17:51:44,087 ERROR [STDERR] javax.naming.NameNotFoundException: MySqlDS not bound


      My ejb-jar.xml inlcudes

      <resource-ref>
      <res-ref-name>MySqlDS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>


      See attached for summary of error log


      Thanks

      Alan

        • 1. Re: Problems Connecting to mysql
          Alan Bryson Newbie

          Sorry the attached files are

          • 2. Re: Problems Connecting to mysql
            Luc Vu Newbie

            Hi Alan,

            I am using the same JBoss+Tomcat. I only add the mysql-service.xml to the deploy directory. My mysql-service.xml is a little different then yours.
            ========== BEGIN mysql-service.xml ========
            <?xml version="1.0" encoding="UTF-8"?>

            <!-- ===================================================================== -->
            <!-- -->
            <!-- JBoss Server Configuration -->
            <!-- -->
            <!-- ===================================================================== -->



            <!-- ==================================================================== -->
            <!-- New ConnectionManager setup for mysql using 2.0.11 driver -->
            <!-- Build jmx-api (build/build.sh all) and view for config documentation -->
            <!-- ==================================================================== -->



            <!--
            MySqlDbRealm
            -->

            <depends optional-attribute-name="ManagedConnectionFactoryName">
            <!--embedded mbean-->


            MySqlDS



            <config-property name="ConnectionURL" type="java.lang.String">jdbc:mysql://localhost:3306/put_your_database_name_here</config-property>
            <config-property name="DriverClass" type="java.lang.String">org.gjt.mm.mysql.Driver</config-property>
            <!--set these only if you want only default logins, not through JAAS -->
            <config-property name="UserName" type="java.lang.String">put_your_database_username_here</config-property>
            <config-property name="Password" type="java.lang.String">put_your_database_password_here</config-property>




            <!--Below here are advanced properties -->
            <!--hack-->
            <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper




            <depends optional-attribute-name="ManagedConnectionPool">
            <!--embedded mbean-->


            0
            50
            5000
            15
            <!--criteria indicates if Subject (from security domain) or app supplied
            parameters (such as from getConnection(user, pw)) are used to distinguish
            connections in the pool. Choices are
            ByContainerAndApplication (use both),
            ByContainer (use Subject),
            ByApplication (use app supplied params only),
            ByNothing (all connections are equivalent, usually if adapter supports
            reauthentication)-->
            ByContainer



            <depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager

            <depends optional-attribute-name="JaasSecurityManagerService">jboss.security:name=JaasSecurityManager

            java:/TransactionManager
            <!--make the rar deploy! hack till better deployment-->
            jboss.jca:service=RARDeployer





            ============ END mysql-service.xml ==========
            Just modify where I say "put_your_database_xxx_here" to customize for your server. Because I put the username and password in the mysql-service.xml, I didn't modify the login-config.xml.

            Your ejb-jar.xml is correct.

            Your ejb code where it look for datasource
            DataSource ds = (DataSource) ic2.lookup("java:MySqlDS");
            shouldn't you add a "/" after "java:" like "java:/MySqlDS".

            I didn't lookup the datasource like you did. What I did is add this to the jboss.xml:

            <enterprise-beans>
            ...
            </enterprise-beans>
            <resource-managers>
            <resource-manager res-class="">
            <res-name>MySqlDS</res-name>
            <res-jndi-name>java:/MySqlDS</res-jndi-name>
            </resource-manager>
            </resource-managers>


            Then in the ebj code, I look for the datasource like this:
            DataSource ds = (DataSource)ctx.lookup("java:comp/env/MySqlDS");

            Hope this help.

            Luc Vu

            • 3. Re: Problems Connecting to mysql
              Luc Vu Newbie

              Hi Alan,

              I am using the same JBoss+Tomcat. I only add the mysql-service.xml to the deploy directory. My mysql-service.xml is a little different then yours.
              ========== BEGIN mysql-service.xml ========
              <?xml version="1.0" encoding="UTF-8"?>

              <!-- ===================================================================== -->
              <!-- -->
              <!-- JBoss Server Configuration -->
              <!-- -->
              <!-- ===================================================================== -->



              <!-- ==================================================================== -->
              <!-- New ConnectionManager setup for mysql using 2.0.11 driver -->
              <!-- Build jmx-api (build/build.sh all) and view for config documentation -->
              <!-- ==================================================================== -->



              <!--
              MySqlDbRealm
              -->

              <depends optional-attribute-name="ManagedConnectionFactoryName">
              <!--embedded mbean-->


              MySqlDS



              <config-property name="ConnectionURL" type="java.lang.String">jdbc:mysql://localhost:3306/put_your_database_name_here</config-property>
              <config-property name="DriverClass" type="java.lang.String">org.gjt.mm.mysql.Driver</config-property>
              <!--set these only if you want only default logins, not through JAAS -->
              <config-property name="UserName" type="java.lang.String">put_your_database_username_here</config-property>
              <config-property name="Password" type="java.lang.String">put_your_database_password_here</config-property>




              <!--Below here are advanced properties -->
              <!--hack-->
              <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper




              <depends optional-attribute-name="ManagedConnectionPool">
              <!--embedded mbean-->


              0
              50
              5000
              15
              <!--criteria indicates if Subject (from security domain) or app supplied
              parameters (such as from getConnection(user, pw)) are used to distinguish
              connections in the pool. Choices are
              ByContainerAndApplication (use both),
              ByContainer (use Subject),
              ByApplication (use app supplied params only),
              ByNothing (all connections are equivalent, usually if adapter supports
              reauthentication)-->
              ByContainer



              <depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager

              <depends optional-attribute-name="JaasSecurityManagerService">jboss.security:name=JaasSecurityManager

              java:/TransactionManager
              <!--make the rar deploy! hack till better deployment-->
              jboss.jca:service=RARDeployer





              ============ END mysql-service.xml ==========
              Just modify where I say "put_your_database_xxx_here" to customize for your server. Because I put the username and password in the mysql-service.xml, I didn't modify the login-config.xml.

              Your ejb-jar.xml is correct.

              Your ejb code where it look for datasource
              DataSource ds = (DataSource) ic2.lookup("java:MySqlDS");
              shouldn't you add a "/" after "java:" like "java:/MySqlDS".

              I didn't lookup the datasource like you did. What I did is add this to the jboss.xml:

              <enterprise-beans>
              ...
              </enterprise-beans>
              <resource-managers>
              <resource-manager res-class="">
              <res-name>MySqlDS</res-name>
              <res-jndi-name>java:/MySqlDS</res-jndi-name>
              </resource-manager>
              </resource-managers>


              Then in the ebj code, I look for the datasource like this:
              DataSource ds = (DataSource)ctx.lookup("java:comp/env/MySqlDS");

              Hope this help.

              Luc Vu

              • 4. Re: Problems Connecting to mysql
                Alan Bryson Newbie

                Thanks for your help it now works.

                Alan

                • 5. Re: Problems Connecting to mysql
                  Alan Bryson Newbie

                  Thanks for your help it now works.

                  Alan

                  • 6. Re: Problems Connecting to mysql
                    Tony Dulin Newbie

                    Would you please tell the version of MySql and the
                    version of the JDBC driver you are using?

                    Thank you.