Since being orked from MySQL back in 2009, MariaDB has become one of the most popular databases of choice for developers over the past decade. While many technologists have likely gravitated to it as a solution due to its open source roots and that it’s rooted in the relational database world, that really only begins to scratch the surface of what MariaDB has to offer.

Over the years MariaDB has diverged from MySQL by adding many features and functionality, much of which we won’t be able to dive into within the context of this article. However, one thing, above all else, has remained the same; providing a modern, open-source, high quality database solution that developers can use to power their innovation.

But before you can dive into MariaDB and check out all it has to offer you’ll need to answer the most fundamental of questions; how do you get started using MariaDB?

MariaDB and Java Database Connectivity (JDBC)

It likely comes as no surprise that Java, and ultimately the Java Virtual Machine (JVM) environment as a whole, has been an extremely popular option used by developers to create applications.

With that in mind, I’ve written this short walkthrough to take you through the steps for getting started with MariaDB (Community Server) using a Docker image, Java and the MariaDB JDBC client.

In this walkthrough you’ll be utilizing MariaDB and JDBC to create a simple (Maven based) “To do” application that, using Java Spring, will expose a variety of endpoints to use to perform basic CRUD (create-read-update-delete) operations on a MariaDB database instance.

Let’s get started!

Requirements

Before jumping into code, you’re going to need to make sure you have a few things on your machine:

  • MariaDB client
  • Docker
  • Java (v. 8+)
  • Curl (for testing the API endpoints)

Creating a new MariaDB instance using Docker

One of the simplest ways to get started with MariaDB, regardless of which operating system you’re using, is to pull the MariaDB Server Docker image, from Docker Hub, and use it create a new container.

To do this simply open a terminal window and run the following:

$ docker run -p 3306:3306 -d --name mariadb -eMARIADB_ROOT_PASSWORD=Password123! mariadb/server:10.4 

That’s it. You should now have a running instance of MariaDB. Pretty painless, right?

You can confirm the instance within a Docker container by running the following:

$ docker ps

And you should see your container within the output.

Connecting to MariaDB

Now that you’ve got a running MariaDB Server instance within a new Docker container the next step will be to connect to and communicate with the database instance using the MariaDB client.

There are many SQL clients available out in the wild. For simplicity’s sake, I’ve chosen to demonstrate how to use the official MariaDB Client, but certainly feel free to use whatever client you prefer.

Connect to your MariaDB instance by executing the following:

$ mariadb --host 127.0.0.1 -P 3306 --user root -pPassword123!

You should see something like the following, which means you’ve successfully connected to the MariaDB instance!

Once you’re connected you can create a new database.

#mariadb #docker #java #spring-boot #spring-data #database #sql #programming

How To Connect MariaDB Docker Containers with Java Spring And JDBC
20.60 GEEK