4 Replies Latest reply on Oct 29, 2002 6:23 PM by adrian.brock

    Setting links to mySQL

    davout

      At what level can I define links from JBoss to a mySQL database?

      Is there just one active link possible at a server level, or can I define multiple database links one for each deployment?

        • 1. Re: Setting links to mySQL

          Typically you bind a DataSource into jndi
          which is a pool of connections to the database.

          There is nothing to stop you creating two DataSources
          with different jndi names for the same database.

          You can map the beans to datasources using
          resource references or resource managers in jboss.xml

          Be careful with commit-option if you are accessing
          the same tables.

          Regards,
          Adrian

          • 2. Re: Setting links to mySQL
            davout

            I'm an EJB newbie... so I would be very grateful if you could help me out with a little more detail about how I achieve this. I'm using JBuilder7 as my IDE.

            To date I've copied the 'mysql-service.xml' file into the 'server/default/deploy/' folder and set this config file so that it points at a specific mySQL database 'test01', like...



            <config-property name="ConnectionURL"
            type="java.lang.String">
            jdbc:mysql://localhost:3306/test01
            </config-property>

            Now I have another prototype bean I have developed that exists in a second mySQL database called 'test01'. How and where do I define the link to this second database?

            • 3. Re: Setting links to mySQL
              davout

              Ok... I'm a EJB/JBoss newbie... how would I go about doing this?

              So far I have deployed the 'mysql-service.xml' file into the 'deploy' folder. This xml file includes definitions that point to a 'test01' mySQL database.

              I now want to create a new link that allows CMP2.0 entity beans to use a second mySQL database called 'test02'. How and where do I setup the links to this second database?


              • 4. Re: Setting links to mySQL

                For the test02
                you just create a mysql2-service.xml

                For the beans:

                jbosscmp-jdbc.xml

                You'll find the dtd in docs/dtd
                look for datasource

                Something like or whatever jndi names you use:


                <ejb-name>MyEntity</ejb-name>
                java:/test01
                <datasource-mapping>mySQL</datasource-mapping>
                ...



                <ejb-name>MyOtherEntity</ejb-name>
                java:/test02
                <datasource-mapping>mySQL</datasource-mapping>
                ...


                You can also set it in at the top of the xml.

                Regards,
                Adrian