MariaDB Connector/J is the official Java Database Connectivity (JDBC) driver for connecting Java applications to MariaDB and MySQL databases. It allows Java programs to interact with databases using the standard JDBC API.
You can include MariaDB Connector/J in your project using build tools like Maven or Gradle, or by manually adding the JAR file to your project's classpath.
a. Using Maven:
Add the following dependency to your pom.xml file:
For production applications, it's highly recommended to use a connection pool to manage database connections efficiently. MariaDB Connector/J can be used with external connection pooling libraries like HikariCP or Apache Commons DBCP, or its own MariaDbPoolDataSource.
MariaDbDataSource: Creates a new connection each time.
MariaDbPoolDataSource: Maintains a pool of connections for reuse.
When using an external pool, configure it to use org.mariadb.jdbc.Driver as the JDBC driver class.