DataSource Creation

STEP 1:
For MySQL
create directory structrue in /jboss/AppServer/jboss-eap-6.4/modules/
com/mysql .with in this create module.xml file with below content and copy driver jar file into this location
module.xml
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
  <resources>
    <resource-root path="mysql-connector-java-5.0.8-bin.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

For MariaDB
copy jar to JBOSS_HOME/modules/org/mariadb/main/
copy jar to JBOSS_HOME/modules/org/mariadb/
create module.xml with the below . Maria DB jar and will beloaded during jboss startup and the class from the jar refered in DataSource for connecting to DB 
<module xmlns="urn:jboss:module:1.1" name="org.mariadb">
    <resources>
        <resource-root path="mariadb-java-client-1.3.3.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>
STEP 2:Install Driver 

Add driver with in <drivers> tag on domain.xml under full-ha profile .This diver will be visible when we create datasouce from JBOSS console .
For mysql
<driver name="mysql" module="com.mysql">
      <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
For db2
 <driver name="mariadb" module="com.mariadb">
     <xa-datasource-class>org.mariadb.jdbc.MariaDbDataSource</xa-datasource-class>
<drivers>
     <driver name="db2" module="com.ibm.db2">
     <driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
 </driver>
For MariaDB
<driver name="mariadb" module="com.mariadb">
     <xa-datasource-class>org.mariadb.jdbc.MariaDbDataSource</xa-datasource-class>
STEP 3:Creation DATA SOURCE 

Login to JBOSS consile using jbadmin
Go to Configuration tab --> Select full-ha profile in dropdown box -->click on ADD Enter Name :MySqlDS JNDI Name:java:/jdbc/MySqlDS 
-->click on next select the previously added driver and click on next
-->Provide Conection url UserName & Password then SAVE and do test connection .

Sample Datasource for DB2 in the config file looks like below .

<subsystem xmlns="urn:jboss:domain:datasources:1.2">
   <datasources>
    <datasource jta="false" jndi-name="java:jboss/datasources/appdb" pool-name="DB-DS" enabled="true" spy="true" use-ccm="false" statistics-enabled="true">
        <connection-url>jdbc:db2://DBHOSTNAME:PORT/DBNAME</connection-url>
        <driver>db2jcc4.jar</driver>
        <transaction-isolation>TRANSACTION_READ_UNCOMMITTED</transaction-isolation>
        <pool>
            <min-pool-size>40</min-pool-size>
            <max-pool-size>200</max-pool-size>
            <flush-strategy>IdleConnections</flush-strategy>
        </pool>
        <security>
           <user-name>dbname</user-name>
            <password>dbpassword</password>
        </security>
        <validation>
            <validate-on-match>false</validate-on-match>
            <background-validation>false</background-validation>
        </validation>
        <timeout>
            <set-tx-query-timeout>false</set-tx-query-timeout>
            <blocking-timeout-millis>120000</blocking-timeout-millis>
            <idle-timeout-minutes>3</idle-timeout-minutes>
            <query-timeout>0</query-timeout>
            <use-try-lock>0</use-try-lock>
            <allocation-retry>0</allocation-retry>
            <allocation-retry-wait-millis>0</allocation-retry-wait-millis>
        </timeout>
        <statement>
            <prepared-statement-cache-size>200</prepared-statement-cache-size>
            <share-prepared-statements>true</share-prepared-statements>
        </statement>
    </datasource>

MariaDB DataSource in the config file looks like below

<xa-datasource jndi-name="java:jboss/datasources/dbname" pool-name="mariadbpool" enabled="true" use-java-context="true" spy="true" use-ccm="false" statistics-enabled="true">
         <xa-datasource-property name="Url">
             jdbc:mariadb://dbhostname:port/dbname
         </xa-datasource-property>
         <xa-datasource-class>org.mariadb.jdbc.MariaDbDataSource</xa-datasource-class>
         <driver>mariadb</driver>
         <new-connection-sql>use tablename</new-connection-sql>
         <transaction-isolation>TRANSACTION_READ_UNCOMMITTED</transaction-isolation>
         <xa-pool>
             <min-pool-size>50</min-pool-size>
             <max-pool-size>100</max-pool-size>
             <prefill>true</prefill>
             <flush-strategy>IdleConnections</flush-strategy>
         </xa-pool>
         <security>
           <user-name>dbname</user-name>
            <password>dbpassword</password>
         </security>
         <validation>
             <check-valid-connection-sql>select 1</check-valid-connection-sql>
             <validate-on-match>true</validate-on-match>
             <background-validation>true</background-validation>
             <background-validation-millis>60000</background-validation-millis>
             <stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.mysqlvalidconnectionchecker"/>
             <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySqlExceptionSorter"/>
         </validation>
         <timeout>
             <blocking-timeout-millis>60000</blocking-timeout-millis>
             <idle-timeout-minutes>10</idle-timeout-minutes>
         </timeout>
         <statement>
             <prepared-statement-cache-size>2000</prepared-statement-cache-size>
             <share-prepared-statements>true</share-prepared-statements>
         </statement>
     </xa-datasource>

Related Posts

One thought on “DataSource Creation

Leave a Reply

Your email address will not be published. Required fields are marked *