5 Replies Latest reply on Aug 31, 2017 10:59 AM by marceloramone

    Datasource connection issue

    marceloramone

      Hello,

       

      I'M trying to test datasource connection.

      The mysql connector driver is installed and registered in my jboss eap 7 - standalone mode.

      It was installed from cli:

       

      module add --name=com.mysql --resources=/home/mmartinez/Descargas/mysql-connector-java-5.1.43/mysql-connector-java-5.1.43-bin.jar --dependencies=javax.api,javax.transaction.api

       

      And registered:

       

      /subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource, driver-class-name=com.mysql.jdbc.Driver)

       

      installed-drivers=[{"driver-name" => "mysql","deployment-name" => undefined,"driver-module-name" => "com.mysql","module-slot" => "main","driver-datasource-class-name" => "","driver-xa-datasource-class-name" => "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource","driver-class-name" => "com.mysql.jdbc.Driver","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}] 

       

      My standalone.xml:

       

      <datasources>

                      <datasource jta="true" jndi-name="java:/datasources/mariadb1" pool-name="mariadb1" enabled="true" use-ccm="true">

                          <connection-url>jdbc:mariadb://localhost:3306/jbossdb1</connection-url>

                          <driver-class>com.mysql.jdbc.Driver</driver-class>

                          <driver>mysql</driver>

                          <security>

                              <user-name>admin</user-name>

                              <password>admin</password>

                          </security>

                          <validation>

                              <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>

                              <background-validation>true</background-validation>

                              <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>

                          </validation>

                      </datasource>

       

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

                              <driver-class>com.mysql.jdbc.Driver</driver-class>

                              <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>

                          </driver>

       

      But when I try to test connection from console management:

       

       

      Failed to create JDBC connection.

      An internal error occurred.

      Unexpected HTTP response: 500

      Request

      {

          "address" => [

              ("subsystem" => "datasources"),

              ("data-source" => "mariadb1")

          ],

          "operation" => "test-connection-in-pool"

      }

      Response

      Internal Server Error

      Unexpected HTTP response: 500

       

      Request

      {

        "address" => [

        ("subsystem" => "datasources"),

        ("data-source" => "mariadb1")

        ],

        "operation" => "test-connection-in-pool"

      }

       

      Response

       

      Internal Server Error

      {

        "outcome" => "failed",

        "failure-description" => "WFLYJCA0040: No se logró invocar la operación: WFLYJCA0047: La conexión no es válida",

        "rolled-back" => true

      }

       

       

       

      I'M running mariadb on fedora 26.

      Of course the db jbossdb1 with user admin with privileges is already created.

       

      console.log:

       

      14:46:54,638 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 58) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection

      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:345)

      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:352)

      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:287)

      at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.createConnectionEventListener(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:1320)

      at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:496)

      at org.jboss.jca.core.connectionmanager.pool.AbstractPool.internalTestConnection(AbstractPool.java:1052)

      at org.jboss.jca.core.connectionmanager.pool.strategy.OnePool.testConnection(OnePool.java:93)

      at org.jboss.as.connector.subsystems.common.pool.PoolOperations$TestConnectionInPool.invokeCommandOn(PoolOperations.java:234)

      at org.jboss.as.connector.subsystems.common.pool.PoolOperations$1.execute(PoolOperations.java:90)

      at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:890)

      at org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:659)

      at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:370)

      at org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1344)

      at org.jboss.as.controller.ModelControllerImpl.internalExecute(ModelControllerImpl.java:392)

      at org.jboss.as.controller.ModelControllerImpl.execute(ModelControllerImpl.java:217)

      at org.jboss.as.domain.http.server.DomainApiHandler.handleRequest(DomainApiHandler.java:212)

      at io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:72)

      at org.jboss.as.domain.http.server.security.SubjectDoAsHandler$1.run(SubjectDoAsHandler.java:72)

      at org.jboss.as.domain.http.server.security.SubjectDoAsHandler$1.run(SubjectDoAsHandler.java:68)

      at java.security.AccessController.doPrivileged(Native Method)

      at javax.security.auth.Subject.doAs(Subject.java:422)

      at org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:92)

      at org.jboss.as.domain.http.server.security.SubjectDoAsHandler.handleRequest(SubjectDoAsHandler.java:68)

      at org.jboss.as.domain.http.server.security.SubjectDoAsHandler.handleRequest(SubjectDoAsHandler.java:63)

      at io.undertow.server.handlers.BlockingHandler.handleRequest(BlockingHandler.java:56)

      at org.jboss.as.domain.http.server.DomainApiCheckHandler.handleRequest(DomainApiCheckHandler.java:95)

      at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)

      at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:792)

      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

      at java.lang.Thread.run(Thread.java:748)

      at org.jboss.threads.JBossThread.run(JBossThread.java:320)

      Caused by: javax.resource.ResourceException: IJ031083: Wrong driver class [com.mysql.jdbc.Driver] for this connection URL [jdbc:mariadb://localhost:3306/jbossdb1]

      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:323)

      ... 31 more

       

      14:46:54,640 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 58) WFLYCTL0013: Operación ("test-connection-in-pool") falló - dirección: ([

          ("subsystem" => "datasources"),

          ("data-source" => "mariadb1")

      ]) - descripción de la falla: "WFLYJCA0040: No se logró invocar la operación: WFLYJCA0047: La conexión no es válida"

       

      Any help please?

       

      Thanks.-

        • 1. Re: Datasource connection issue
          rhn-support-abhati

          Hi,

           

          Can you please confirm if your database server is up and running properly.

           

          Also please check the connection URL is correct or not.

           

          Please confirm if your database is up and running , please test the connection again and share the standalone.xml/server.log file for further analysis

          • 2. Re: Datasource connection issue
            andey

            Hi,

             

            A datasource class must implement "javax.sql.DataSource" rather than "java.sql.Driver".

             

            You should configure the datasource class with "<datasource-class>" as like below:

             

            ~~~

            ...

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

               <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>

            </driver>

            ...

            ~~~

             

            - Try removing the <driver-class>com.mysql.jdbc.Driver</driver-class> from driver section. I don't think that should be needed.

            - Try removing <driver-class>com.mysql.jdbc.Driver</driver-class> from datasource section, this is not required

            - Also check the "connection-url" settings:

            • 3. Re: Datasource connection issue
              marceloramone

              @Anup Day,

               

              Thank you for the comment.

               

              I made the changes you suggested but the problem persist.

               

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

                                     <!-- <driver-class>com.mysql.jdbc.Driver</driver-class> -->

                                      <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>

               

              Test de connection:

               

              10:36:45,505 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 65) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection

              at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:345)

              at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:352)

              at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:287)

              at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.createConnectionEventListener(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:1320)

              at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:496)

              at org.jboss.jca.core.connectionmanager.pool.AbstractPool.internalTestConnection(AbstractPool.java:1052)

              at org.jboss.jca.core.connectionmanager.pool.strategy.OnePool.testConnection(OnePool.java:93)

              at org.jboss.as.connector.subsystems.common.pool.PoolOperations$TestConnectionInPool.invokeCommandOn(PoolOperations.java:234)

              at org.jboss.as.connector.subsystems.common.pool.PoolOperations$1.execute(PoolOperations.java:90)

              at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:890)

              at org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:659)

              at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:370)

              at org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1344)

              at org.jboss.as.controller.ModelControllerImpl.internalExecute(ModelControllerImpl.java:392)

              at org.jboss.as.controller.ModelControllerImpl.execute(ModelControllerImpl.java:217)

              at org.jboss.as.domain.http.server.DomainApiHandler.handleRequest(DomainApiHandler.java:212)

              at io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:72)

              at org.jboss.as.domain.http.server.security.SubjectDoAsHandler$1.run(SubjectDoAsHandler.java:72)

              at org.jboss.as.domain.http.server.security.SubjectDoAsHandler$1.run(SubjectDoAsHandler.java:68)

              at java.security.AccessController.doPrivileged(Native Method)

              at javax.security.auth.Subject.doAs(Subject.java:422)

              at org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:92)

              at org.jboss.as.domain.http.server.security.SubjectDoAsHandler.handleRequest(SubjectDoAsHandler.java:68)

              at org.jboss.as.domain.http.server.security.SubjectDoAsHandler.handleRequest(SubjectDoAsHandler.java:63)

              at io.undertow.server.handlers.BlockingHandler.handleRequest(BlockingHandler.java:56)

              at org.jboss.as.domain.http.server.DomainApiCheckHandler.handleRequest(DomainApiCheckHandler.java:95)

              at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)

              at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:792)

              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

              at java.lang.Thread.run(Thread.java:748)

              at org.jboss.threads.JBossThread.run(JBossThread.java:320)

              Caused by: javax.resource.ResourceException: IJ031083: Wrong driver class [com.mysql.jdbc.Driver] for this connection URL [jdbc:mariadb://localhost:3306/jbossdb1]

              at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:323)

              ... 31 more

               

               

              10:36:45,507 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 65) WFLYCTL0013: Operación ("test-connection-in-pool") falló - dirección: ([

                  ("subsystem" => "datasources"),

                  ("data-source" => "mariadb1")

              ]) - descripción de la falla: "WFLYJCA0040: No se logró invocar la operación: WFLYJCA0047: La conexión no es válida"

               

              @Arnav Bhati

               

               

              mariadb server  and jboss server are running:

               

               

              ● mariadb.service - MariaDB 10.1 database server

                 Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)

                 Active: active (running) since Thu 2017-08-31 10:23:13 -03; 27min ago

                Process: 3576 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)

                Process: 3514 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)

                Process: 3492 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)

              Main PID: 3549 (mysqld)

                 Status: "Taking your SQL requests now..."

                  Tasks: 26 (limit: 4915)

                 CGroup: /system.slice/mariadb.service

                         └─3549 /usr/libexec/mysqld --basedir=/usr

               

               

              ago 31 10:23:12 lab systemd[1]: Starting MariaDB 10.1 database server...

              ago 31 10:23:12 lab mysql-prepare-db-dir[3514]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.

              ago 31 10:23:12 lab mysql-prepare-db-dir[3514]: If this is not the case, make sure the /var/lib/mysql is empty before running mysql-prepare-db-dir.

              ago 31 10:23:12 lab mysqld[3549]: 2017-08-31 10:23:12 140415311956224 [Note] /usr/libexec/mysqld (mysqld 10.1.26-MariaDB) starting as process 3549 ...

              ago 31 10:23:13 lab systemd[1]: Started MariaDB 10.1 database server.

               

               

              ● jboss-eap-rhel.service - SYSV: JBoss EAP startup script

                 Loaded: loaded (/etc/rc.d/init.d/jboss-eap-rhel.sh; generated; vendor preset: disabled)

                 Active: active (running) since Thu 2017-08-31 10:33:09 -03; 17min ago

                   Docs: man:systemd-sysv-generator(8)

                Process: 3854 ExecStart=/etc/rc.d/init.d/jboss-eap-rhel.sh start (code=exited, status=0/SUCCESS)

              Main PID: 3945 (java)

                  Tasks: 69 (limit: 4915)

                 CGroup: /system.slice/jboss-eap-rhel.service

                         ├─3871 /bin/sh /opt/jboss-eap-7.0/bin/standalone.sh -c standalone.xml

                         └─3945 java -D[Standalone] -server -verbose:gc -Xloggc:/opt/jboss-eap-7.0/standalone/log/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps

               

               

              ago 31 10:32:57 lab systemd[1]: Starting SYSV: JBoss EAP startup script...

              ago 31 10:32:57 lab runuser[3869]: pam_unix(runuser:session): session opened for user mmartinez by (uid=0)

              ago 31 10:32:57 lab runuser[3869]: pam_unix(runuser:session): session closed for user mmartinez

              ago 31 10:32:57 lab jboss-eap-rhel.sh[3854]: Starting jboss-eap: /

              ago 31 10:33:09 lab jboss-eap-rhel.sh[3854]: [  OK  ]

              ago 31 10:33:09 lab systemd[1]: jboss-eap-rhel.service: Supervising process 3945 which is not our child. We'll most likely not notice when it exits.

              ago 31 10:33:09 lab systemd[1]: Started SYSV: JBoss EAP startup script.

              • 4. Re: Datasource connection issue
                andey

                - Verify  the <connection-url> whether its working properly or not.

                 

                ~~~

                <datasources>

                                <datasource jta="true" jndi-name="java:/datasources/mariadb1" pool-name="mariadb1" enabled="true" use-ccm="true">

                                    <connection-url>jdbc:mariadb://localhost:3306/jbossdb1</connection-url>

                                    <driver-class>com.mysql.jdbc.Driver</driver-class>

                ...

                ~~~

                 

                Remove the <driver-class> from datasource section. I don't think that should be needed. If that doesn't work details on how you installed the module will be required.

                 

                 

                Check whether you have followed the below steps  to install a JDBC driver as a core module:

                 

                1.Create a directory under $JBOSS_HOME/modules. In this example: "$JBOSS_HOME/modules/com/oracle/jdbc/main".

                2.Put the the JDBC driver jar in this directory.

                 

                3.Create a module configuration file module.xml:

                ~~~

                <module xmlns="urn:jboss:module:1.1" name="com.oracle.jdbc">
                  <resources>
                  <resource-root path="ojdbc6.jar"/>
                  </resources>
                  <dependencies>
                  <module name="javax.api"/>
                  <module name="javax.transaction.api"/>
                  </dependencies>
                </module>

                ~~~

                 

                Note that the jdbc driver jar must contain a META-INF/services/java.sql.Driver text file that specifies the jdbc Driver, otherwise the Java service provider mechanism used to load the driver will not work. From the main/common vendors only Informix does not have this out of the box.

                • 5. Re: Datasource connection issue
                  marceloramone

                  @Anup Day,

                   

                   

                  Thanks again for your help.

                   

                   

                  The driver-class is already removed from datasources section:

                   

                   

                   

                   

                  <datasources>

                                  <datasource jta="true" jndi-name="java:/datasources/mariadb1" pool-name="mariadb1" enabled="true" use-ccm="true">

                                      <connection-url>jdbc:mariadb://localhost:3306/jbossdb1</connection-url>

                                     <!-- <driver-class>com.mysql.jdbc.Driver</driver-class> -->

                                      <driver>mysql</driver>

                                      <security>

                                          <user-name>admin</user-name>

                                          <password>admin</password>

                                      </security>

                                      <validation>

                                          <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>

                                          <background-validation>true</background-validation>

                                          <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>

                                      </validation>

                                  </datasource>

                   

                   

                  The driver was installed as a deploy following the instructions here: https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html/configuration_guide/datasource_management

                   

                   

                  13.2.1. Install a JDBC Driver as a Core Module

                   

                   

                  ls -ltr /opt/jboss-eap-7.0/modules/com/mysql/main

                  total 980

                  -rw-rw-r--. 1 mmartinez mmartinez 999018 ago 30 12:17 mysql-connector-java-5.1.43-bin.jar

                  -rw-rw-r--. 1 mmartinez mmartinez    312 ago 30 12:17 module.xml

                   

                   

                  cat module.xml

                  <?xml version="1.0" ?>

                   

                   

                  <module xmlns="urn:jboss:module:1.1" name="com.mysql">

                   

                   

                      <resources>

                          <resource-root path="mysql-connector-java-5.1.43-bin.jar"/>

                      </resources>

                   

                   

                      <dependencies>

                          <module name="javax.api"/>

                          <module name="javax.transaction.api"/>

                      </dependencies>

                   

                   

                   

                   

                  The jar contains the file you mentioned:

                   

                   

                  /META-INF/services/java.sql.Driver:

                   

                   

                  com.mysql.jdbc.Driver

                  com.mysql.fabric.jdbc.FabricMySQLDriver

                   

                   

                  I'M trying to test the connection URL.