8 Replies Latest reply on May 7, 2015 8:14 AM by Sreekanth Munarai

    DataSource Error

    Sreekanth Munarai Expert

      Hi All,

       

      I tried to create datasource connection in JBoss EAP 6.3.

       

      I have followed all the basic steps as follows:

           1.  Downloaded mysql-connector-java-5.1.34-bin.jar and placed it under com/mysql/main

           2. Created module.xml as below

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

                         <properties>

                        <property name="jboss.api" value="unsupported"/>

                    </properties>

                    <resources>

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

                        <!-- Insert resources here -->

                              </resources>

                              <dependencies>

                             <module name="javax.api"/>

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

                        <module name="javax.servlet.api" optional="true"/>

                    </dependencies>

                     </module>

           3. Added the below changes in Standalone.xml:

                <datasource jndi-name="java:jboss/datasources/sqlDS" pool-name="sqlDS" enabled="true" use-java-context="true">

                               <connection-url>jdbc:mysql:sqlserver://IP:Port/UAT;loginTimeout=80</connection-url>

                               <driver>mysql</driver>

                               <security>

                                  <user-name>TEST</user-name>

                                   <password>TEST123</password>

                               </security>

                           </datasource>

                           <drivers>

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

                               </driver>

                           </drivers>

       

      When trying to start the server getting below error:

      ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 25) JBAS014612: Operation ("add") failed - address: ([

          ("subsystem" => "datasources"),

          ("jdbc-driver" => "mysql")

      ]): org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.mysql is already registered

        at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:158) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

        at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:236) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

        at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:742) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

       

      When i try to access thru console, driver was already enabled. Tried to test connection found below exception:

      Unexpected HTTP response: 500

      Request

      {    "address" => [

              ("subsystem" => "datasources"),

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

          ],

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

      }

      Response

      Internal Server Error

      {    "outcome" => "failed",

          "failure-description" => "JBAS010440: failed to invoke operation: JBAS010442: failed to match pool. Check JndiName: java:jboss/datasources/sqlDS",

          "rolled-back" => true}

       

      Please advise your suggestions.Thanks

      Sreekant

        • 1. Re: DataSource Error
          Abhijit Humbe Master

          Hi,

          The MySQL driver version 5.1.30 and up has two driver classes registered in META-INF/services/java.sql.Driver

           

          com.mysql.jdbc.Driver
          com.mysql.fabric.jdbc.FabricMySQLDriver

           

          Can you try with following driver tag and check

          <drivers>
            <driver name="mysql" module="com.mysql.jdbc">
            <driver-class>com.mysql.jdbc.Driver</driver-class>
            <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
            </driver>

          • 2. Re: DataSource Error
            Sreekanth Munarai Expert

            Hi Abhijit,

             

            I tried your above suggestion however i still have the same issue.

            Additionally, i have encountered a new error as below

             

            ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 25) JBAS014612: Operation ("add") failed - address: ([

                ("subsystem" => "datasources"),

                ("jdbc-driver" => "mysql")

            ]) - failure description: "JBAS010441: Failed to load module for driver [com.mysql.jdbc]"

            INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report

            JBAS014775:    New missing/unsatisfied dependencies:

                  service jboss.jdbc-driver.mysql (missing) dependents: [service jboss.data-source.java:jboss/datasources/mysqlDS, service jboss.driver-demander.java:jboss/datas

            ources/mysqlDS]


            Is there anything I'm missing in driver configuration?

            Driver using :mysql-connector-java-5.1.21.jar

             

            Please share your inputs.

            Thanks,

            Sreekanth

            • 3. Re: DataSource Error
              Abhijit Humbe Master

              Hi Sreekanth,

               

              Can you confirm you are using correct module  in driver tag ? As per my understanding you have places mysql jar under "com.mysql" directory but in "driver" tag you are using "com.mysql.jdbc" which causing this exception. Use correct module module and give a try.

              • 4. Re: DataSource Error
                Sreekanth Munarai Expert

                Hi Abhijit,

                I was in big mistake. I was under impression that i was using MySql database.but i was wrong. We ahve MS-SQL server.

                I have downloaded the needed jdbc driver to connect Ms-SQL i.e. sqljdbc4.jar file. Placed the jar file under /com/microsoft/main

                Made the required changes in module.xml as below:

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

                    <properties>

                        <property name="jboss.api" value="unsupported"/>

                    </properties>

                    <resources>

                        <resource-root path="sqljdbc4.jar"/>

                        <!-- Insert resources here -->

                    </resources>

                    <dependencies>

                        <module name="javax.api"/>

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

                        <module name="javax.servlet.api" optional="true"/>

                    </dependencies>

                </module>

                 

                Standalone.xml changes as below:

                     <datasources>

                              <datasource jndi-name="java:jboss/datasources/sqlDS" pool-name="sqlDS" enabled="true" use-java-context="true">

                                    <connection-url>jdbc:microsoft:sqlserver://IP:Port/UAT;loginTimeout=80</connection-url>

                                    <driver>sql</driver>

                                    <security>

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

                                        <password>******</password>

                                    </security>

                                </datasource>

                                <drivers>

                                    <driver name="sql" module="com.microsoft">

                  <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>

                  <xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>

                                    </driver>

                                </drivers>

                            </datasources>



                Started JBoss without any errors/exception. However, when i tried to test connection thru console, Connection is failed.

                getting below error in my cmd:

                     Caused by: javax.resource.ResourceException: Wrong driver class [class com.microsoft.sqlserver.jdbc.SQLServerDriver] for this connection URL      [jdbc:microsoft:sqlserver://IP:Port/UAT;loginTimeout=80]

                     at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:298)      [ironjacamar- jdbc1.0.26

                     .Final-redhat-1.jar:1.0.26.Final-redhat-1].

                 

                I tried all the way changing the driver class tag. But still I'm under same issue.

                Please help me with your findings.Thanks

                • 5. Re: DataSource Error
                  Abhijit Humbe Master

                  Hi,

                  It looks tobe an issue with connection URL, can you please try with following URL

                  ~~~

                  jdbc:sqlserver://host:port;databaseName=DB_Name

                  ~~~

                  • 6. Re: DataSource Error
                    Sreekanth Munarai Expert

                    Thanks a ton Abhijit!!!

                    Your above suggestion worked!!!!

                    is that means we have to mention "host:port;databaseName=DB_Name" but not as "jdbc:microsoft:sqlserver://IP:Port/DBname"

                    is it gonna be same for any other Database servers or its varies DB to DB(ex oracle,mysql etc).

                    Please share suggestions/advises which can be used in future use.

                    Thanks again!!!

                    • 7. Re: DataSource Error
                      Abhijit Humbe Master

                      Hi,

                      Good to know it works..!!

                      DB URL's are almost same for every DB, but it changes little bit for according to DB.  Here are the few DB URL which I use at my end:

                       

                      Oracle: jdbc:oracle:thin:@host:Port:DB_Name

                      Mysql:  jdbc:mysql://lhost:Port/DB_Name

                      DB2:    jdbc:db2://host:Port/DB_Name

                      MSsql: jdbc:sqlserver://host:port;databaseName=DB_Name

                      • 8. Re: DataSource Error
                        Sreekanth Munarai Expert

                        Thanks a lot Abhi for your inputs/suggestions.