6 Replies Latest reply on Sep 19, 2002 11:30 PM by Wayne L. Andersen

    Session bean using MySQL

    Wayne L. Andersen Newbie

      I think I am really close on this but I may need an example.

      I have configured mysql and added the driver and the mysql-service.xml to the deploy dir.

      I have created a .jsp page that references a bean that references my mysql database.

      I think I am doing something wrong in either the jboss.xml or ejb-jar.xml files when configuring the datasource reference.

      Can someone give me an example that shows the correct entries in the jboss.xml and ejb-jar.xml and the code used in the bean to open a connection using that setup.

      When I deploy my mysql-service.xml file it tells me that the name is java:/agencyDS.

      My ejb-jar.xml has a section like this:
      <resource-ref>
      <res-ref-name>jdbc/agencyDS</res-ref-name>
      <res-type>java.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      My jboss.xml has this:
      <resource-ref>
      <res-ref-name>jdbc/agencyDS</res-ref-name>
      <jndi-name>java:/agencyDS</jndi-name>
      </resource-ref>

      In my bean I am doing this:
      InitialContext ic = new InitialContext();
      dataSource = (DataSource)ic.lookup("jdbc/Agency");


      I don't understand why this does not work, I get a datasource not bound error.

        • 1. Re: Session bean using MySQL
          Joel Vogt Master

          try including with your jboss.xml and ejb-jar.xml a jaws.xml. Otherwise jboss uses standardjaws.xml which only defines DefaultDS.

          Basically find standardjaws.xml and make your own with only the mysql bits included. This is where you will want to define your custom finders later on too.

          Hope this helps.

          • 2. Re: Session bean using MySQL
            Wayne L. Andersen Newbie

            Ok, I edited the standard jaws.xml and included a version for my bean in the META-INF.

            The error that I am getting is:
            java.rmi.ServerException: Bean exception. Notify the application administrator; nested exception is:
            javax.ejb.EJBException: AgencyBean: Error connecting to jdbc/Agency:
            javax.naming.NameNotFoundException: jdbc not bound;

            • 3. Re: Session bean using MySQL
              patrick Novice

              I had something simulair.
              Try to get rid of the jdbc prefi in the jndi stuff and just name it. Maybe that will work.

              Do not know why it does not work with jdbc/ infront of it

              Or try java:/Name

              In the jmx viewer you can get a list of all bound jndi names

              • 4. Re: Session bean using MySQL
                Ryan Delano Newbie


                Unless I am missing something (aside from not knowing what JBoss/Tomcat versions you are running) I'd say you only need to do this:

                Change this:
                dataSource = (DataSource)ic.lookup("jdbc/Agency");

                To This:
                dataSource = (DataSource)ic.lookup("java:/agencyDS");

                I should note that in all my comparable examples and projects I DID NOT have any support in my ejb-jar.xml file. I also was not *required* to create jboss.xml so I didn't! (meaning it worked without one, so I didn't bother)

                I simply defined the datasource in mysql-service.xml and then used the exact name that is output when deploying that xml file. (Of course not as my first try, but it made sense and worked immediately when I did.) It seems you are all set on the -service.xml file, if not let me know and I can gather more info.

                As always, please post a follow up and let others know what works or what does not.

                thanks & good luck,
                Ryan

                • 5. Re: Session bean using MySQL
                  Ryan Delano Newbie


                  Unless I am missing something (aside from not knowing what JBoss/Tomcat versions you are running) I'd say you only need to do this:

                  Change this:
                  dataSource = (DataSource)ic.lookup("jdbc/Agency");

                  To This:
                  dataSource = (DataSource)ic.lookup("java:/agencyDS");

                  I should note that in all my comparable examples and projects I DID NOT have any support in my ejb-jar.xml file. I also was not *required* to create jboss.xml so I didn't! (meaning it worked without one, so I didn't bother)

                  I simply defined the datasource in mysql-service.xml and then used the exact name that is output when deploying that xml file. (Of course not as my first try, but it made sense and worked immediately when I did.) It seems you are all set on the -service.xml file, if not let me know and I can gather more info.

                  As always, please post a follow up and let others know what works or what does not.

                  thanks & good luck,
                  Ryan

                  • 6. Re: Session bean using MySQL
                    Wayne L. Andersen Newbie

                    I made a mistake here the 'jdbc/agency' is actually 'java:/comp/env/jdbc/agency' in my bean. Which shows exactly like that in the jmx-console jndilist screen.