Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add new Datasource (mysql) wildfly

I'm trying to add new datasource mysql jdbc driver to my wildfly server

I created folder wildfly.x.x.x/modules/system/layers/base/com/mysql/main I've got here jdbc jar file and module.xml

<module xmlns="urn:jboss:module:1.3" name="com.mysql">
        <resources>
         <resource-root path="mysql-connector-java-5.1.34-bin.jar"/>
     </resources>
     <dependencies>
      <module name="javax.api"/>
     </dependencies>
    </module>

then added dataresource code into standalone-full.xml (under datareources tag)

 <datasource jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS"     enabled="true" use-java-context="true">
 <connection-url>jdbc:mysql://localhost:3306/test</connection-url>
 <driver>MySQLDriver</driver>
<security>
 <user-name>root</user-name>
 <password></password>
</security>
</datasource>

but when i go to wildfly control panel http://localhost:9990/console/ dataresource doesnt appear , what did i missed?

also i'm trying to add it manually from interface i'v got this error

Unexpected HTTP response: 500

Request
{
    "address" => [
        ("subsystem" => "datasources"),
        ("data-source" => "mysql")
    ],
    "operation" => "test-connection-in-pool"
}

Response

Internal Server Error
{
    "outcome" => "failed",
    "failure-description" => "JBAS010440: failed to invoke operation: JBAS010447: Connection is not valid",
    "rolled-back" => true
} 
like image 898
Gtopuria Avatar asked Jan 11 '15 13:01

Gtopuria


2 Answers

Did you add a driver definition? Your datasources subsystem should look something like this:

    <subsystem xmlns="urn:jboss:domain:datasources:2.0">
        <datasources>
            <datasource jndi-name="java:/jdbc/myds" pool-name="myds" enabled="true" use-java-context="true">
                <connection-url>jdbc:mysql://localhost/mydb</connection-url>
                <driver>mysql</driver>
                <security>
                    <user-name>foo</user-name>
                    <password>bar</password>
                </security>
            </datasource>
            <drivers>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
                <driver name="mysql" module="com.mysql">
                    <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                </driver>
            </drivers>
        </datasources>
    </subsystem>

The driver element in the data source definition must reference a driver element by name. The module attribute must match the name of your MySQL driver module.

like image 154
Harald Wellmann Avatar answered Sep 28 '22 02:09

Harald Wellmann


Actually I meet the same problem (I could add the datasources and test connection successfully before) So I'm just confused and I find a way works for me:)

See my services and I find it stopped,and I started it then tried again,It works well again! Even though your service does not stop, maybe just restart it. I have to say it may not work for you if you never success to connect before,good luck~

enter image description here

enter image description here

like image 41
Zero Avatar answered Sep 28 '22 01:09

Zero