11 Replies Latest reply on Feb 18, 2005 12:25 PM by fbiaggi

    connecting to mysql

    teddyert

      Does anyone know a good guide on how to set up a connection from jboss to a mysql database? I have found some information about it, but it didnt work properly.

        • 1. Re: connecting to mysql
          pablojavierpy

          You should prepare a "data source configuration" deployment file.

          Those files are deploying by dropping them in the "deploy" directory of your running AppServer as usual. As far as I know They must end with "-ds" suffix. For example:

          myapp-ds.xml

          For MySQL, a practical example can be:

          <?xml version="1.0" encoding="UTF-8"?>
          
          <!-- ========================================== -->
          <!-- -->
          <!-- JBoss Server Configuration -->
          <!-- -->
          <!-- ========================================== -->
          
          <!-- ========================================== -->
          <!-- Datasource config for MySQL -->
          <!-- ========================================== -->
          
          <datasources>
           <local-tx-datasource>
           <jndi-name>MyAppMySQLConnection</jndi-name>
           <connection-url>jdbc:mysql://localhost/mysqldatabase</connection-url>
           <driver-class>org.gjt.mm.mysql.Driver</driver-class>
           <user-name>mysqluser</user-name>
           <blocking-timeout-millis>500</blocking-timeout-millis>
           <password>mysqlpassword</password>
           </local-tx-datasource>
          </datasources>
          


          Don't forget to place MySQL JDBC driver in server's lib directory before you even start JBOSS.

          Hope this help.

          • 2. Re: connecting to mysql
            teddyert

            I have copied this fie into the deploy directory, but when I try to connect I get the following error:
            no ClassLoaders found for com.mysql.jdb.Driver

            Any idea what can be wrong?

            • 3. Re: connecting to mysql
              fbiaggi

              Hi,
              with version of the mysql jdbc driver do you use ?
              Have you place it in the /server/default(or?)/lib/ directory ?
              Ev. try:
              <driver-class>com.mysql.jdbc.Driver</driver-class>

              • 4. Re: connecting to mysql
                fbiaggi

                Hi again,
                I think that in your "com.mysql.jdb.Driver" a 'c' is missing in the .jdb.

                • 5. Re: connecting to mysql
                  teddyert

                  ops, of course you are right. Thats just a typo in the post. Sorry about that. I think it is version 3.1.

                  • 6. Re: connecting to mysql
                    pablojavierpy

                    Re your sure that com.mysql.jdbc.Driver is driver class for MySQL JDBC's implementation?

                    As fbiaggi stated, make sure that driver's jar is in:

                    $JBOSS_HOME/server/default/lib directory "before" you start JBOSS.

                    Hope this helps.

                    • 7. Re: connecting to mysql
                      teddyert

                      thanks for all the help

                      I have tried a new driver, and I think I got a little bit closer.

                      The error I get now is:
                      Could not create connection
                      Communication exception during handshake

                      • 8. Re: connecting to mysql
                        pablojavierpy

                        Can you post your "-ds.xml" file?

                        • 9. Re: connecting to mysql
                          fbiaggi

                          Hi,
                          this seem to be an authorisation or connection problem.
                          Are you using a local or remote instance of mysql ?
                          To test it edit the user table in the mysql database (ex. with mysql query browser),
                          open a new user with an empty host/userid/password and give Y to all privililedges.
                          Restart mysql and retry, if now works you have found the problem.

                          • 10. Re: connecting to mysql
                            teddyert

                            It worked!
                            Thank you

                            • 11. Re: connecting to mysql
                              fbiaggi

                              Good,
                              pay attention that your mysql is now open to all users on any system with all auth.