MariaDB Java Connector

Install the Java Connector on Rocky Linux 9.

If you are new to Java or struggling with the installation of MariaDB Java Connector on Linux, the following guide will take you from start to finish.


Requirements

To complete this blog, you will need a server with network connectivity and external internet access. Make sure to open the relevant firewalls. For testing purposes, high-specification servers are not required. You can use local virtual machines instead. In this guide, we will be using Digital Ocean Droplets with 2 vCPUs and 4GB RAM. All commands will be executed as the root user on the servers, using a RockyLinux 9 operating system. However, you can also use other flavours of Linux, such as CentOS.


Ensure the server you are using is up to date and install the Linux wget package:

Bash
yum update -y
yum install -y wget

I like to ensure my server has a hostname so that when I have multiple windows open, I know exactly where I am:

Bash
hostnamectl set-hostname application

Once you have set the hostname, log out and log back in again, and the hostname will be displayed.


Java comes with many versions and options, to keep things simple we will install the Open JDK version 21 of Java. As we are going to compile our script we need the development version and therefore add the -devel to the rpm name.

Bash
yum install -y java-21-openjdk-devel

You can test that Java is available by checking the version:

Bash
java --version

You should see the version of Java returned to the screen:

Bash
openjdk 21.0.2 2024-01-16 LTS
OpenJDK Runtime Environment (Red_Hat-21.0.2.0.13-1) (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.2.0.13-1) (build 21.0.2+13-LTS, mixed mode, sharing)

Next, we need to get the Java Connector from the MariaDB Downloads page, at the time of writing the latest version is 3.3.2-GA. This will install the jar file into the shared Java directory on the server:

Bash
wget https://dlm.mariadb.com/3700566/Connectors/java/connector-java-3.3.2/mariadb-java-client-3.3.2.jar -P /usr/share/java/

To use the MariaDB Database Connector, we must make sure it is in our classpath, we can do this by running this command:

Bash
export CLASSPATH=$CLASSPATH:/usr/share/java/mariadb-java-client-3.3.2.jar

For this to persist you will need to update your profile as well, there are various ways to do this, but for now, we will do:

Bash
echo export CLASSPATH=$CLASSPATH:/usr/share/java/mariadb-java-client-3.3.2.jar >> ~/.bashrc

You should now have the MariaDB Java Connector and Open JDK installed on your Linux Server.


Now that you have the Java connector installed, you can follow my guide to create a simple Java Application to connect to your MariaDB databases.

Kester Riley

Kester Riley is a Senior Solutions Engineer who leverages his website to establish his brand and build strong business relationships. Through his blog posts, Kester shares his expertise as a consultant, mentor, trainer, and presenter, providing innovative ideas and code examples to empower ambitious professionals.

CentOS (15) Connector (5) Continuous Availability (1) Cooperative Monitoring (3) High Availability (12) Java (3) MariaDB (16) MaxScale (14) Python (2) Replica Rebuild (10) Rocky Linux (15)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.