In Red Hat JBoss Enterprise Application Platform (JBoss EAP), you can find datasoure configurations within the datasource subsystem, in the domain.xml or standalone.xml files.
The data source subsystem has the following structure:
<subsystem xmlns="urn:jboss:domain:datasources:6.0">
<datasources>
<datasource jndi-name="java:jboss/datasourcse/ExampleDS"
jta="true"
pool-name="ExampleDS"
enabled="true"
use-java-context="true">
<connection-url>jdbc:h2:mem:test</connection-url>
<driver>h2</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>sa</user-name>
<password>sa</password
</security>
<validation>
<valid-connection-checker class-name="..."/>
<validate-on-match>true</validate-on-match>
<exception-sorter class-name="..."/>
</validation>
<timeout>
<blocking-timeout-millis>1000</blocking-timeout-millis>
<idle-timeout-minutes>3</idle-timeout-minutes>
</timeout>
<statement>...</statement>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">...</driver>
<driver name="mariadb" module="org.mariadb">...</driver>
</drivers>
</datasources>
</subsystem>The JNDI name used to look up the data source. | |
The name of the management pool for the datasource. | |
Dictates whether the data source is enabled or disabled. | |
Dictates whether to bind the data source to global JNDI. | |
The JDBC driver connection URL. | |
The connection pool settings. | |
Security credentials for connecting to the database. | |
The validation strategies for the data source connections. | |
Contains child elements which are timeout settings. | |
Describes the configuration for the behavior of prepared statements. | |
The available drivers definitions. |
Any number of <datasource> entries within the <datasources> subsystem can be defined.
Each data source requires a unique JNDI name, assigned using the jndi-name attribute.
Components that need to obtain a database connection from a pool use the jndi-name value to look up the pool in the JNDI naming service.
A valid JNDI name for a data source must start with java: or java:/jboss, for example, java:/jboss/datasources/bookstore.
Some pool configurations in the <pool> section include <min-pool-size>, <max-pool-size>, and <prefill>.
The <prefill> configuration attempts to populate the connection pool when the pool is initially created.
The <validation> section allows for various settings for validating database connections in the pool.
Connection validation is discussed later in this section.
The <statement> section configures the behavior of prepared statements.
The available options are, <prepared-statement-cache-size>, for specifying the number of prepared statements to cache per connection, and <share-prepared-statements> for specifying if non-closed prepared statements can be reused.
Another <statement> configuration is <track-statements>, which can be set to true, false or nowarn.
This is a useful option because, when set to true or nowarn, it closes database connections and result sets that were not explicitly closed by the application when the connection is returned to the pool.
The <drivers> section is for defining JDBC drivers that are deployed as modules.
The name attribute for the driver corresponds to the value used in the <datasource> definition.
The module attribute must be assigned to a deployed module on the server.
The XSD schema file for the datasources subsystem section is in the docs/schema directory of the EAP installation in a file called wildfly-datasources_6_0.xsd.
JBoss EAP can manage outages, network problems, database maintenance, or any other event that can cause the server to lose connection to the database. Using one of several validation methods, users can configure and customize when and how to validate the database connection and how to handle the loss of connection.
To configure when to validate connections JBoss EAP has the validate-on-match and the background-validation options.
To configure how to validate connections JBoss EAP has the valid-connection-checker-class-name and the check-valid-connection-sql options.
You can configure validations by editing the server configuration file as explained in the following sections.
If the validate-on-match value is set to true, then the connection validates every time it is pulled from the connection.
The following is an example of using the validate-on-match method:
<datasources>
<datasource ...>
<validation>
<validate-on-match>true</validate-on-match>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
</datasources>If the background-validation value is set to true, then the connection validates based on the value set in the <background-validation-millis>.
The following is an example of using the background-validation method:
<datasources>
<datasource ...>
<validation>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
</datasources>Can be | |
The class name for the exception sorter, specific to the database vendor. |
Both validation methods can be defined, however only one can be enabled at a time.
JBoss EAP provides several classes that can be used to validate a database connection that is specific to the relational database management system in use. For example, for a MySQL validation class checker, displays as follows:
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
This validation mechanism requires the user to provide as SQL statement to validate the connection. The following is an example for a MySQL database connection:
<check-valid-connection-sql>select 1</check-valid-connection-sql>
By using an exception sorter, users can provide a class to properly detect and clean up after fatal connection exceptions. JBoss EAP provides several exception sorter classes based on the relational database management system in use. The following is an example for a MySQL exception sorter:
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
The EAP management console provides a way to create a data source by using templates that are preconfigured for different database vendors. The following steps can be used to create a non-XA data source with the management console in a standalone server.
Click from the top of the management console and aviagate to to access the non-XA data source page. Then click in the drop-down menu.
![]() |
Select a database template and click . If none of them are valid, then select the option and see the JDBC driver documentation to complete the following steps.
![]() |
Enter the datasource attributes and click .
![]() |
Select a database driver in the drop-down menu and click .
![]() |
Enter the connection URL, username, and password for the database and click .
![]() |
Click to verify that the datasource can connect to the database. Note that if you test the connection at this step, then the management console creates the datasource. You can click and test the connection later.
On the final step, notice that the connection URL is formatted for the correct MySQL syntax. Click to finish creating the data source.
Finally, a window with a configuration summary shows and you can click .
![]() |
The management console provides a button to verify that the connections from a connection pool can access the database.
![]() |
Likewise, the management CLI can be used to test if the data source was correctly configured. To validate it, use the following command:
[standalone@localhost /] /subsystem=datasources/\
data-source=datasource_name:test-connection-in-poolYou can create data sources by using the management CLI.
For example, the following command creates a MySQL datasource, called MySqlDS, with connection validation configured:
[standalone@localhost] data-source add --name=MySqlDS --jndi-name=java:jboss/MySqlDS \
--driver-name=mysql \
--connection-url=jdbc:mysql://localhost:3306/jbossdb \
--user-name=admin --password=admin \
--validate-on-match=true --background-validation=false \
--valid-connection-checker-class-name=\
org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker \
--exception-sorter-class-name=\
org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorterIn this case, the data source validates each connection as it is pulled from the connection pool by using the MySQLValidConnectionChecker validation class.
The previous command generates the following datasource configuration in the datasource subsystem:
<datasources> <datasource jndi-name="java:jboss/MySqlDS" pool-name="MySqlDS"><connection-url>jdbc:mysql://localhost:3306/jbossdb</connection-url> <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"/> <validate-on-match>true</validate-on-match>
<background-validation>false</background-validation> <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/> </validation> </datasource> </datasources>
The JNDI name that would be used to look up the data source by a component on the EAP server. | |
The name that refers to the driver that is defined in the | |
The credentials used to access the MySQL database. | |
Both validate on match and background validation are defined, but only one of them can be enabled. |
You can use a similar command in domain mode to add a data source to a specific profile:
[domain@localhost] data-source add --name=MySqlDS --profile=full-ha \
--jndi-name=java:jboss/MySqlDS --driver-name=mysql \
--connection-url=jdbc:mysql://localhost:3306/jbossdb \
--user-name=admin --password=admin \
--validate-on-match=true --background-validation=false \
--valid-connection-checker-class-name=\
org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker \
--exception-sorter-class-name=\
org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorterFor more information, refer to the Creating Datasources section in the Datasource Management chapter in the Red Hat Red Hat Jboss Enterprise Application Platform 7.4 Configuration Guide documentation at https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/html-single/configuration_guide/index#adding_datasources
For more information, refer to the Modifying Datasources section in the Datasource Management chapter in the Red Hat Red Hat Jboss Enterprise Application Platform 7.4 Configuration Guide documentation at https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/html-single/configuration_guide/index#modifying_datasources
For more information, refer to the Removing Datasources section in the Datasource Management chapter in the Red Hat Red Hat Jboss Enterprise Application Platform 7.4 Configuration Guide documentation at https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/html-single/configuration_guide/index#removing_datasources