7 Replies Latest reply on May 20, 2015 3:11 AM by jholusa

    How to select <driver-class> when driver is installed as deployment

    jholusa

      Hi,

       

      I have following scenario. I want to use MySQL datasource, I have mysql-connector-java-5.1.33-bin.jar copied in the SERVER/standalone/deployments and the datasource is not being loaded. According to 2 driver classes in the latest MySQL JDBC driver causes a stacktrace , since Connector/J version 5.1.30+ there are multiple classes in java.sql.Driver file. When I manually delete one of the entries, everything works fine. According to the thread, I have to specify <driver-class> and my question is where? I figured out something like this:

       

      <datasource jta="true" jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExamplePool" enabled="true" use-java-context="true">
           <connection-url>...</connection-url>
           <driver-class>com.mysql.jdbc.Driver</driver-class>
           <driver>mysql-connector-java-5.1.33-bin.jar</driver>
           ...
       </datasource>
      

      But this is not working, datasource is still not being loaded. I saw plenty of examples with <drivers>/<driver> element, but this applies only if I have the driver installed as core module correct? Note that I have to use EAP 6.4, where this issue is not fixed.

       

      What am I doing wrong?

        • 1. Re: How to select <driver-class> when driver is installed as deployment
          mmusaji

          I have mysql-connector-java-5.1.33-bin.jar copied in the SERVER/standalone/deployments and the datasource is not being loaded.

          ....

          What am I doing wrong?

           

          Why are you deploying your driver to the deployments directory in the first place? Install it as a module which is the recommended approach and then that driver can be used by all your applications. This is the benefit of using modules. Otherwise you get in to classloading issues and adding dependencies to your deployment(s) which gets complicated very quickly.

          • 2. Re: How to select <driver-class> when driver is installed as deployment
            lafr
            • 3. Re: How to select <driver-class> when driver is installed as deployment
              jholusa

              Hi Mustafa,

               

              exactly as Frank says, quoting from documentation: "The recommended way to install a JDBC driver into WildFly 8 is to deploy it as a regular JAR deployment."

              • 4. Re: How to select <driver-class> when driver is installed as deployment
                jamezp

                If you execute the following CLI command you'll see some information about the drivers deployed.

                /subsystem=datasources:read-attribute(name=installed-drivers)
                

                 

                Output:

                {
                    "outcome" => "success",
                    "result" => [
                        {
                            "driver-name" => "mysql-connector-java-5.1.35-bin.jarcom.mysql.jdbc.Driver_5_1",
                            "deployment-name" => "mysql-connector-java-5.1.35-bin.jarcom.mysql.jdbc.Driver_5_1",
                            "driver-module-name" => undefined,
                            "module-slot" => undefined,
                            "driver-datasource-class-name" => undefined,
                            "driver-xa-datasource-class-name" => undefined,
                            "driver-class-name" => "com.mysql.jdbc.Driver",
                            "driver-major-version" => 5,
                            "driver-minor-version" => 1,
                            "jdbc-compliant" => false
                        },
                        {
                            "driver-name" => "mysql-connector-java-5.1.35-bin.jarcom.mysql.fabric.jdbc.FabricMySQLDriver_5_1",
                            "deployment-name" => "mysql-connector-java-5.1.35-bin.jarcom.mysql.fabric.jdbc.FabricMySQLDriver_5_1",
                            "driver-module-name" => undefined,
                            "module-slot" => undefined,
                            "driver-datasource-class-name" => undefined,
                            "driver-xa-datasource-class-name" => undefined,
                            "driver-class-name" => "com.mysql.fabric.jdbc.FabricMySQLDriver",
                            "driver-major-version" => 5,
                            "driver-minor-version" => 1,
                            "jdbc-compliant" => false
                        },
                        {
                            "driver-name" => "h2",
                            "deployment-name" => undefined,
                            "driver-module-name" => "com.h2database.h2",
                            "module-slot" => "main",
                            "driver-datasource-class-name" => "",
                            "driver-xa-datasource-class-name" => "org.h2.jdbcx.JdbcDataSource",
                            "driver-class-name" => "org.h2.Driver",
                            "driver-major-version" => 1,
                            "driver-minor-version" => 3,
                            "jdbc-compliant" => true
                        }
                    ]
                }
                

                 

                You'll notice the driver-name for the two different driver names. I think you can specify the driver name instead of the driver class.

                 

                The linked JIRA was for WildFly so it should be fixed there. I'm not sure if it's fixed in EAP 6.x or not though.

                 

                --

                James R. Perkins

                • 5. Re: How to select <driver-class> when driver is installed as deployment
                  mmusaji

                  Yeah my apologies, I thought this was for EAP 6.x as original post did say you had to use EAP 6.x. In EAP 6.x the recommended way is to install it as a module.

                  • 6. Re: How to select <driver-class> when driver is installed as deployment
                    heiko.braun

                    Apart from the what the documentation says, a module is certainly the recommended and more reliable way. In particular when using the domain mode.

                    • 7. Re: How to select <driver-class> when driver is installed as deployment
                      jholusa

                      (Sorry for late reply)

                       

                      Thanks James,  this was exactly what I needed. I would never come up with this