Home Ask Login Register

Developers Planet

Your answer is one click away!

Nandor February 2016

Can't use mysql driver with Wildfly 9.0.2 however It seems like it's loaded correctly

I'm trying to switch to wildfly from glassfish but I'm getting a hard time to set up a connection to mysql db. I have placed the .jar and module.xml under /wildfly-9.0.2.Final/modules/system/layers/base/com/mysql/driver/main.

The content of module.xml:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mysql.driver">
  <resource-root path="mysql-connector-java-5.1.38-bin.jar"/>              
  <module name="javax.api"/>
  <module name="javax.transaction.api"/>

In standalone.xml I've added an entry:

<driver name="mysql" module="com.mysql.driver">

And here comes the fun part, when I run ./standalnole.sh there is no error at all. It says mysql driver stared, but on the Management Interface under datasources - detected drivers I don't see it, just the original h2 driver.

[0m13:22:59,551 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver service with driver-name = mysql

Do you know any solution to this problem?


jon martin solaas February 2016

I installed a postgresql-driver and module using the commandline interface. It ended up in .../wildfly-9.0.2.Final/modules/org/postgresql/main/ . Thats a different place than you have used, but I do not know if that's the problem here.

Your xml look ok to me, but the driver jar and module.xml file is perhaps not in the correct place. Try to use cli to install it. Here is how I installed my driver and created datasource for it:

module add --name=org.postgresql --resources=/Users/jonmartinsolaas/Downloads/postgresql-9.4.1207.jar --dependencies=javax.api,javax.transaction.api

When adding the module jar-files are copied into wildfly. If you need more than one jar, use : as list separator.

    data-source add \
 --name=myDS \
 --driver-name=postgresql \
 --jndi-name=java:jboss/datasources/myDS \
 --connection-url="jdbc:postgresql://localhost/my-db" \
 --user-name=username \
 --password=secret \
 --use-ccm=false \
 --max-pool-size=25 \
 --blocking-timeout-wait-millis=5000 \
 --new-connection-sql="set datestyle = ISO, European;" \
 --check-valid-connection-sql="select 1" \

And if you need XA datasource:

   xa-data-source add \
    --name=mydsXA \
    --driver-name=postgresql \
    --jndi-name=java:jboss/datasources/mydsXA \
    --user-name=username \
    --password=secret \
    --recovery-username= username \
    --recovery-password = secret \
    --check-valid-connection-sql="select 1" \
    --use-ccm=false \
    --max-pool-size=25 \
    --blocking-timeout-wait-millis=5000 \
    --new-connection-sql="set datestyle = ISO, European;" \


jersey-city-ninja February 2016

I see a couple of issues. First of all, you did not deploy it. Simplest way is to drop the mysql-connector-java-<version>.jar into <wildfly dir>/standalone/deployments.

Secondly, you did not configure your datasource in standalone.xml. Something like:

<subsystem xmlns="urn:jboss:domain:datasources:2.0">
        <datasource jta="true" jndi-name="java:/MySQLDataSource" pool-name="MySQLDataSource" enabled="true" use-java-context="true" spy="false" use-ccm="true">
            <driver>mysql-connector-java-<my version>.jar</driver>

Post Status

Asked in February 2016
Viewed 2,275 times
Voted 5
Answered 2 times


Leave an answer

Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved