Bookmark this page

Configuring JDBC Drivers

Objectives

  • Deploy a JDBC Driver as a module.

  • Configure a driver in the data source subsystem.

Deploying a JDBC Driver as a Module

Java Database Connectivity (JDBC) is a Java API to communicate with relational databases. A JDBC driver is a component that implements the JDBC API. Java applications use the JDBC driver to perform database operations. A JDBC driver is packaged in a Java Archive (JAR) file, and contains a class file with the driver definition. JDBC drivers are available from database vendors, such as from MariaDB or PostgreSQL. To use a JDBC driver in Red Hat JBoss Enterprise Application Platform (JBoss EAP), you first need install the driver as a module on the server.

You can add the JDBC driver module manually or with the management CLI. The module add management CLI command requires the user to provide:

  • Name: A name based on a Java package name that JBoss EAP uses to store the JAR file and a module configuration file. The name must be unique and cannot conflict with the existing libraries available at the $JBOSS_HOME/modules directory.

  • Resources: Refers to the location that stores the JAR file.

  • Dependencies: Identify which JBoss EAP modules are used by the JDBC driver.

The syntax for the module add command is:

[disconnected /] module add \
--name=<module_name> \
--resources=<JDBC_Driver> \
--dependencies=<library1>,<library2>,...

For example, the following command in the management CLI creates the JDBC PostreSQL module by using the file postgresql-42.x.y.jar that the database vendor provides:

[disconnected /] module add \
--name=com.postgresql \
--resources=/path/to/postgresql-42.x.y.jar \
--dependencies=javaee.api,sun.jdk,ibm.jdk,javax.api,javax.transaction.api

Note

You can run this command in the management CLI disconnected mode.

This command creates the /opt/jboss-eap-7.4/modules/com/postgresql/main directory with the JDBC JAR file and a module.xml with the dependencies you specify in the command.

The following module.xml file defines a module for the PostgreSQL JDBC driver:

<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="com.postgresql">
  <resources>
    <resource-root path="postgresql-42.x.y.jar"/>
  </resources>
  <dependencies>
    <module name="javaee.api"/>
    <module name="sun.jdk"/>
    <module name="ibm.jdk"/>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

Note

If you need to remove a module from JBoss EAP, then you can stop the server, and run the following command:

[disconnected /] module remove --name=<module_name>

Defining Drivers

After adding the driver as a module, the next step is to create a <driver> definition in the <drivers> section of the data source subsystem in the JBoss EAP configuration file.

You can use the following management CLI operation to add the <driver> definition on a standalone server:

/subsystem=datasources/jdbc-driver=<driver_name>:add\
(driver-module-name=<module_name>,driver-name=<unique_driver_name>)

In the driver definition command, the following fields are required:

  • driver-name: A unique name for the driver.

  • driver-module-name: The unique name from the module installed at the $JBOSS_HOME/modules directory.

For the managed domain mode, the syntax is as follows:

/profile=<profile_name>/subsystem=datasources/jdbc-driver=<
driver_name>:add\
(driver-module-name=<module_name>,driver-name=<unique_driver_name>)

For example, in a managed domain, use the following management CLI command to define the PostgresSQL driver in the default profile:

[domain@172.25.250.254 /] /profile=default/subsystem=datasources/jdbc-driver=mysql:add(\
           driver-module-name=com.postgresql,\
           driver-name=postgresql\
)

Note

When you define the driver with the management CLI, the domain.xml or the standalone.xml configuration file shows additional tags that are similar to the following driver tag:

<drivers>
    <driver name="postgresql" module="com.postgresql"/>
</drivers>

After defining the <driver> in the <drivers> section of the data source subsystem, the driver is referenced by its name attribute and users can create data sources that use the driver.

References

For more information, see the JDBC Drivers 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#jdbc_drivers

For more information about how to configure different vendor drivers, see the Example Datasource Configurations 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#example_datasource_configurations

For more information about vendors tested integrations, see the Red Hat JBoss Enterprise Application Platform (EAP) 7 Supported Configurations knowledge base article at https://access.redhat.com/articles/2026253#TestedIntegrations74

Revision: ad248-7.4-18a9db2