1
votes

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">
  <resources>
  <resource-root path="mysql-connector-java-5.1.38-bin.jar"/>              
  </resources>
<dependencies>
  <module name="javax.api"/>
  <module name="javax.transaction.api"/>
</dependencies>
</module>

In standalone.xml I've added an entry:

<driver name="mysql" module="com.mysql.driver">
   <driver-class>com.mysql.jdbc.Driver</driver-class>
</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?

2
Do you by chance of a screen shot by chance? I don't have a problem seeing it. - James R. Perkins
Did you follow the steps mentioned on Wildfly 9 docs DataSource configuration? - António Ribeiro
There's a chance you don't see it in the management interface because it isn't being used. did you try adding a datasource that requires it? - teacurran

2 Answers

0
votes

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" \
 --enabled=true

And if you need XA datasource:

batch
   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;" \
    --enabled=true

    /subsystem=datasources/xa-data-source=paddaXA/xa-datasource-properties=ServerName:add(value=localhost)
    /subsystem=datasources/xa-data-source=paddaXA/xa-datasource-properties=PortNumber:add(value=5432)
    /subsystem=datasources/xa-data-source=paddaXA/xa-datasource-properties=DatabaseName:add(value=my-db)
run-batch

Note that the XA definition runs as a batch (sort-of transaction) so you have to "commit" using run-batch.

0
votes

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">
    <datasources>
        <datasource jta="true" jndi-name="java:/MySQLDataSource" pool-name="MySQLDataSource" enabled="true" use-java-context="true" spy="false" use-ccm="true">
            <connection-url>jdbc:mysql://localhost:3306/mydatabase</connection-url>
            <driver-class>com.mysql.jdbc.Driver</driver-class>
            <driver>mysql-connector-java-<my version>.jar</driver>
            <pool>
                <allow-multiple-users>false</allow-multiple-users>
            </pool>
            <security>
                <user-name>xxx</user-name>
                <password>xxx</password>
            </security>
            <validation>
                <validate-on-match>false</validate-on-match>
                <background-validation>false</background-validation>
                <use-fast-fail>false</use-fast-fail>
            </validation>
            <timeout>
                <set-tx-query-timeout>false</set-tx-query-timeout>
                <blocking-timeout-millis>0</blocking-timeout-millis>
                <idle-timeout-minutes>0</idle-timeout-minutes>
                <query-timeout>0</query-timeout>
                <use-try-lock>0</use-try-lock>
                <allocation-retry-wait-millis>0</allocation-retry-wait-millis>
            </timeout>
            <statement>
                <track-statements>NOWARN</track-statements>
                <share-prepared-statements>false</share-prepared-statements>
            </statement>
        </datasource>
    </datasources>
</subsystem>