Bookmark this page

Guided Exercise: Configuring JDBC Drivers

Install the MariaDB JDBC driver as a module, and enable it in the server configuration.

Resources
Files: /home/jboss/mariadb-java-client-3.2.0.jar
Application URL: N/A

Outcomes

You should be able to install a MariaDB JDBC driver as a module by using the management CLI.

Before beginning the guided exercise, run the following command to prepare the exercise environment:

[student@workstation ~]$ lab start datasources-drivers

Instructions

  1. Start the management CLI as the jboss user.

    [student@workstation ~]$ cd /opt/jboss-eap-7.4/bin
    [student@workstation bin]$ sudo -u jboss ./jboss-cli.sh
    You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
  2. Create the module.

    You can find the MariaDB JDBC JAR file in the /home/jboss directory.

    Installing the driver as a module makes it available to any Red Hat JBoss Enterprise Application Platform (JBoss EAP) instance.

    Use the following management CLI command to create the module by pointing to the JDBC JAR file, listing the JAR's dependencies and using the MariaDB driver vendor ID as the name:

    [disconnected /] module add --name=com.mariadb \
    --resources=/home/jboss/mariadb-java-client-3.2.0.jar \
    --dependencies=javaee.api,sun.jdk,ibm.jdk,javax.api,javax.transaction.api

    Open a new terminal in workstation, and validate that the driver installs as a module by listing the JBOSS_HOME/modules/com/mariadb/main directory. Verify that the directory contains the module.xml and mariadb-java-client-3.2.0.jar files:

    [student@workstation ~]$ ls /opt/jboss-eap-7.4/modules/com/mariadb/main
    module.xml  mariadb-java-client-3.2.0.jar

    Also, verify that the module.xml file generates correctly by comparing it with the following listing:

    <?xml version='1.0' encoding='UTF-8'?>
    
    <module xmlns="urn:jboss:module:1.1" name="com.mariadb">
    
        <resources>
            <resource-root path="mariadb-java-client-3.2.0.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>
  3. Define the MariaDB driver.

    Connect to a running JBoss EAP instance to define the MariaDB Driver.

    1. Open a new terminal window and start a standalone instance with /home/student/AD248/labs/datasources-drivers/standalone as the base directory:

      [student@workstation ~]$ cd /opt/jboss-eap-7.4/bin
      [student@workstation bin]$ ./standalone.sh \
      -Djboss.server.base.dir=/home/student/AD248/labs/datasources-drivers/standalone
      ...output omitted...
      05:43:21,271 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: JBoss EAP 7.4.11.GA (WildFly Core 15.0.26.Final-redhat-00001) started in 3566ms - Started 318 of 557 services (343 services are lazy, passive or on-demand)
      
      ...output omitted...
    2. Return to the terminal that runs the management CLI in disconnected mode. Use the following command to connect to the running instance of JBoss EAP:

      [disconnected /] connect localhost:9990

      If prompted, provide admin as the username and redhat123 as the password. Verify that the following prompt shows:

      [standalone@localhost:9990 /]
    3. Use the following command to define the MariaDB driver by specifying the JBoss EAP module:

      [standalone@localhost:9990 /] /subsystem=datasources\
      /jdbc-driver=mariadb:add(driver-name=mariadb,driver-module-name=com.mariadb)
      {"outcome" => "success"}

      Notice that the driver-module-name has the`com.mariadb` value from the module.xml file.

  4. Verify the driver configuration.

    Use the following command to inspect the new MariaDB JDBC driver:

    [standalone@localhost:9990 /] /subsystem=datasources\
    /jdbc-driver=mariadb:read-resource
    {
        "outcome" => "success",
        "result" => {
            "deployment-name" => undefined,
            "driver-class-name" => undefined,
            "driver-datasource-class-name" => undefined,
            "driver-major-version" => undefined,
            "driver-minor-version" => undefined,
            "driver-module-name" => "com.mariadb",
            "driver-name" => "mariadb",
            "driver-xa-datasource-class-name" => undefined,
            "jdbc-compliant" => undefined,
            "module-slot" => undefined,
            "profile" => undefined,
            "xa-datasource-class" => undefined
        }
    }
  5. Clean up.

    1. Exit the management CLI:

      [standalone@localhost:9990 /] exit
    2. Stop the instance of JBoss EAP by pressing Ctrl+C in the terminal window that is running JBoss EAP.

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish datasources-drivers

Revision: ad248-7.4-18a9db2