JDBC 4.2 compatible driver providing comprehensive database connectivity for MariaDB and MySQL servers
npx @tessl/cli install tessl/maven-org-mariadb-jdbc--mariadb-java-client@3.5.0MariaDB Connector/J is a comprehensive JDBC 4.2 compatible driver that provides high-performance database connectivity for Java applications connecting to MariaDB and MySQL databases. It offers enterprise-grade features including connection pooling, high availability configurations, SSL/TLS security, comprehensive authentication methods, and extensive configuration options for both simple applications and complex enterprise deployments.
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.5.3</version>
</dependency>import java.sql.*;
import javax.sql.*;
import org.mariadb.jdbc.*;For advanced features:
import org.mariadb.jdbc.export.*;
import org.mariadb.jdbc.plugin.*;
import org.mariadb.jdbc.type.*;import java.sql.*;
// Simple connection
String url = "jdbc:mariadb://localhost:3306/mydb";
Connection conn = DriverManager.getConnection(url, "user", "password");
// Execute query
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
while (rs.next()) {
System.out.println(rs.getString("name"));
}
// Prepared statement
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO users (name, email) VALUES (?, ?)");
pstmt.setString(1, "John Doe");
pstmt.setString(2, "john@example.com");
pstmt.executeUpdate();
// Clean up
rs.close();
stmt.close();
pstmt.close();
conn.close();The MariaDB JDBC driver is built around several key architectural components:
Core connection functionality for establishing and managing database connections with comprehensive configuration options, SSL/TLS security, and multi-host support.
public class Driver implements java.sql.Driver {
public Connection connect(String url, Properties props) throws SQLException;
public static Connection connect(Configuration configuration) throws SQLException;
public boolean acceptsURL(String url) throws SQLException;
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException;
}
public class Connection implements java.sql.Connection {
public void cancelCurrentQuery() throws SQLException;
// Standard JDBC Connection methods...
}DataSource implementations for connection pooling, XA transactions, and enterprise application server integration with comprehensive JNDI support.
public class MariaDbDataSource implements DataSource, ConnectionPoolDataSource, XADataSource {
public Connection getConnection() throws SQLException;
public Connection getConnection(String username, String password) throws SQLException;
public PooledConnection getPooledConnection() throws SQLException;
public XAConnection getXAConnection() throws SQLException;
public void setUrl(String url);
public String getUrl();
}
public class MariaDbPoolDataSource extends MariaDbDataSource implements Closeable, AutoCloseable {
public void close() throws SQLException;
}Comprehensive configuration system with 100+ options for connection behavior, performance tuning, security settings, and high availability configuration.
public class Configuration {
public static Configuration parse(String url, Properties props) throws SQLException;
// Connection properties
public String user();
public String password();
public String database();
public List<HostAddress> addresses();
public HaMode haMode();
// SSL/TLS properties
public SslMode sslMode();
public String serverSslCert();
public String keyStore();
public String trustStore();
// Performance properties
public boolean useCompression();
public boolean cachePrepStmts();
public int prepStmtCacheSize();
public boolean useServerPrepStmts();
}Multi-host connection support with automatic failover, load balancing, and replication awareness for enterprise-grade availability.
public enum HaMode {
NONE, REPLICATION, SEQUENTIAL, LOADBALANCE, LOAD_BALANCE_READ;
public Optional<HostAddress> getAvailableHost(
List<HostAddress> hostAddresses,
ConcurrentMap<HostAddress, Long> denyList,
boolean primary
);
}
public class HostAddress {
public static HostAddress from(String host, int port);
public static HostAddress from(String host, int port, boolean primary);
public static HostAddress pipe(String pipe);
public static HostAddress localSocket(String localSocket);
public static List<HostAddress> parse(String spec, HaMode haMode);
}Comprehensive statement execution support including prepared statements, callable statements, batch operations, and streaming result sets.
public class Statement implements java.sql.Statement {
// Standard JDBC Statement methods
}
public class ClientPreparedStatement extends BasePreparedStatement {
// Client-side prepared statement implementation
}
public class ServerPreparedStatement extends BasePreparedStatement {
// Server-side prepared statement implementation
}
public class BaseCallableStatement extends BasePreparedStatement implements CallableStatement {
// Callable statement for stored procedures and functions
}Comprehensive data type support including JDBC standard types, MariaDB-specific extensions, geometry types, and LOB handling.
public class MariaDbBlob implements Blob, Serializable {
// BLOB implementation
}
public class MariaDbClob extends MariaDbBlob implements Clob, NClob {
// CLOB/NCLOB implementation
}
// Geometry types (package: org.mariadb.jdbc.type)
public interface Geometry {
// Base geometry interface for spatial data types
static Point parsePoint(boolean littleEndian, ReadableByteBuf buf);
static Geometry getGeometry(ReadableByteBuf buf, int length, Column column) throws SQLDataException;
}
public class Point implements Geometry {
// Point geometry type for spatial coordinates
}
public class Polygon implements Geometry {
// Polygon geometry type for spatial regions
}Pluggable authentication system supporting multiple authentication methods, credential providers, and SSL/TLS security configurations.
public interface AuthenticationPlugin {
String type();
boolean mustUseSsl();
// Authentication implementation methods
}
public interface CredentialPlugin extends Supplier<Credential> {
String type();
default boolean mustUseSsl();
default String defaultAuthenticationPluginType();
default CredentialPlugin initialize(Configuration conf, String userName, HostAddress hostAddress) throws SQLException;
}
public enum SslMode {
DISABLE, TRUST, VERIFY_CA, VERIFY_FULL;
}Built-in connection pooling with lifecycle management, JMX monitoring, and configurable pool behavior for enterprise applications.
public class MariaDbPoolConnection implements PooledConnection, XAConnection {
public Connection getConnection() throws SQLException;
public void close() throws SQLException;
public void addConnectionEventListener(ConnectionEventListener listener);
public XAResource getXAResource() throws SQLException;
}
public interface PoolMBean {
// JMX monitoring interface
int getActiveConnections();
int getIdleConnections();
int getTotalConnections();
}public enum TransactionIsolation {
READ_UNCOMMITTED(Connection.TRANSACTION_READ_UNCOMMITTED),
READ_COMMITTED(Connection.TRANSACTION_READ_COMMITTED),
REPEATABLE_READ(Connection.TRANSACTION_REPEATABLE_READ),
SERIALIZABLE(Connection.TRANSACTION_SERIALIZABLE);
}
public class MariaDbXid implements Xid {
public MariaDbXid(int formatId, byte[] globalTransactionId, byte[] branchQualifier);
public int getFormatId();
public byte[] getGlobalTransactionId();
public byte[] getBranchQualifier();
}
public class MaxAllowedPacketException extends SQLException {
// Exception for packet size limits
}