3 Replies Latest reply on Jun 16, 2007 11:14 AM by jdijkmeijer

    JBOSS 4.2.0 & MySQL

    Edwin vanManen Newbie

      Hi we are students from the Netherlands.
      We study at Hogeschool Utrecht.

      We want JBOSS 4.2.0 to work in combination with our MySQL database for our project.

      The documentation we found:
      * http://www.onjava.com/pub/a/onjava/2004/02/25/jbossjdbc.html
      * http://wiki.jboss.org/wiki/Wiki.jsp?page=SetUpMysqlAsDefaultDS
      describes jaws.xml or standardjaws.xml

      JBOSS 4.2.0 does not have jaws.xml in server/default/conf !

      Now we are mad, we feel frustrated we want an answer !
      We feel fucked up because we need to deal with this shit !
      Please help us out. Because our school says we have to work with JBOSS and the teachers dont even know how it works themselves.
      And we are getting a headache here from all the bullshit search-results on google.

      Thanx for helping us out !

        • 1. Re: JBOSS 4.2.0 & MySQL
          Avihai Marchiano Novice

          The instructions are only in case that you want it as default.

          you dont need to make it default in order to use it.

          just follow until step -3 and change the name of the data source in the data source file to MySqlDs

          • 2. Re: JBOSS 4.2.0 & MySQL
            Andrew Dale Newbie

            Hi,

            I would create a mysql-ds.xml file in /deploy. I have copied the standard example one that comes with JBoss 4.0.4/5 (it should hopefully just work with 4.2.0GA as well):

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

            <!-- $Id: mysql-ds.xml 41016 2006-02-07 14:23:00Z acoliver $ -->
            <!-- Datasource config for MySQL using 3.0.9 available from:
            http://www.mysql.com/downloads/api-jdbc-stable.html
            -->

            <datasources>
             <local-tx-datasource>
             <jndi-name>MySqlDS</jndi-name>
             <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb</connection-url>
             <driver-class>com.mysql.jdbc.Driver</driver-class>
             <user-name>x</user-name>
             <password>y</password>
             <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
             <!-- should only be used on drivers after 3.22.1 with "ping" support
             <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
             -->
             <!-- sql to call when connection is created
             <new-connection-sql>some arbitrary sql</new-connection-sql>
             -->
             <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
             <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
             -->
            
             <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
             <metadata>
             <type-mapping>mySQL</type-mapping>
             </metadata>
             </local-tx-datasource>
            </datasources>
            


            On startup this file will be deployed, and now you can use it with ejb3 e.t.c

            Cheers,

            Andy

            • 3. Re: JBOSS 4.2.0 & MySQL
              jdijkmeijer Newbie

              I have had the same a few times: configuring jboss to use mysql as default database, so I wrote a simple ant task

              Not sure if 4.2 is complete, it worked well for 4.0.2 (I made a few changes, for 4.2 standardjaws has been replaces by standardjbosscmp-jdbc) but the server starts without a error.

              have funnn

              <?xml version="1.0"?>
              
              <project name="mysql" default="mysql" basedir=".">
              
               <property name="jboss_home" value="/Applications/jboss-4.2.0.GA/"/>
               <property name="server_conf" value="server/default"/>
               <property name="dburl" value="jdbc:mysql://localhost/jboss"/>
               <property name="dbuser" value="jboss"/>
               <property name="dbpassword" value="jboss"/>
               <property name="mysql_lib_dir" value="/Users/jahoo/dev/testsvn/resources/lib12GA"/>
               <property name="mysql_file" value="mysql-connector-java-5.0.5-bin.jar"/>
              
               <target name="mysql"
               description="does change mysql to standard db">
               <copy file="${mysql_lib_dir}/${mysql_file}" tofile="${jboss_home}/${server_conf}/lib/${mysql_file}"/>
               <delete file="${jboss_home}/${server_conf}/deploy/hsqldb-ds.xml"/>
               <copy file="${jboss_home}/docs/examples/jca/mysql-ds.xml" tofile="${jboss_home}/${server_conf}/deploy/mysql-ds.xml"/>
               <replaceregexp file="${jboss_home}/${server_conf}/deploy/mysql-ds.xml" match="MySqlDS" replace="DefaultDS"/>
               <replaceregexp file="${jboss_home}/${server_conf}/deploy/mysql-ds.xml" match="<connection-url>.*</connection-url>" replace="<connection-url>${dburl}</connection-url>"/>
               <replaceregexp file="${jboss_home}/${server_conf}/deploy/mysql-ds.xml" match="user-name>.*<" replace="user-name>${dbuser}<"/>
               <replaceregexp file="${jboss_home}/${server_conf}/deploy/mysql-ds.xml" match="password>.*<" replace="password>${dbpassword}<"/>
               <replace file="${jboss_home}/${server_conf}/conf/standardjbosscmp-jdbc.xml" token="<type-mapping>Hypersonic SQL</type-mapping>" value="<type-mapping>mySQL</type-mapping>"/>
               <replace file="${jboss_home}/${server_conf}/conf/standardjbosscmp-jdbc.xml" token="<fk-constraint>false</fk-constraint>" value="<fk-constraint>true</fk-constraint>"/>
               <delete file="${jboss_home}/${server_conf}/deploy/jms/hsqldb-jdbc2-service.xml"/>
               <delete file="${jboss_home}/${server_conf}/deploy/jms/hsql-jdbc2-service.xml"/>
               <copy file="${jboss_home}/docs/examples/jms/mysql-jdbc2-service.xml" tofile="${jboss_home}/${server_conf}/deploy/jms/mysql-jdbc2-service.xml"/>
               <replace file="${jboss_home}/${server_conf}/deploy/jms/mysql-jdbc2-service.xml" token="MySqlDS" value="DefaultDS" />
               <replace file="${jboss_home}/${server_conf}/conf/login-config.xml" token="<policy>">
               <replacetoken><![CDATA[<policy>
              <application-policy name = "MySqlDbRealm">
               <authentication>
               <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
               <module-option name = "principal">jboss</module-option>
               <module-option name = "userName">jboss</module-option>
               <module-option name = "password">jboss</module-option>
               <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=DefaultDS</module-option>
               </login-module>
               </authentication>
              </application-policy>
              ]]></replacetoken>
               </replace>
              </target>
              </project>