MariaDB Connector/J Release SeriesSupported Java Version(s)MariaDB Connector/J 2.0 and aboveJava 11, Java 8MariaDB Connector/J 1.8Java 11, Java 8, Java 7MariaDB Connector/J 1.6 and 1.7Java 11, Java 8, Java 7, Java 6Installing MariaDB Connector/JMariaDB Connector/J can be installed using, or by manually putting the.jar file in your. See for more information.MariaDB Connector/J.jar files and source code tarballs can be downloaded from the following URL:.MariaDB Connector/J.jar files can also be downloaded from the following URL:.Installing DependenciesJNA (net.java.dev.jna:jna) and JNA-PLATFORM (net.java.dev.jna:jna-platform) 4.2.1 or greater are also needed when you would like to connect to the server with Unix sockets or windows pipes. Using the DriverThe following subsections show the formatting of JDBC connection strings forMariaDB and MySQL database servers. Additionally, sample code is provided thatdemonstrates how to connect to one of these servers and create a table.
Getting a New ConnectionThere are two standard ways to get a connection: Using DriverManagerThe preferred way to get a connection with MariaDB Connector/J is to use the class.When the DriverManager class is used to locate and load MariaDB Connector/J, the application needs no further configuration. The DriverManager class will automatically load MariaDB Connector/J and allow it to be used in the same way as any other JDBC driver.For example: Connection connection = DriverManager.getConnection('jdbc:mariadb://localhost:3306/DB?user=root&password=myPassword'). The legacy way of loading a JDBC driver also still works for MariaDB Connector/J. E.g.: Class.forName('org.mariadb.jdbc.Driver') Having MariaDB and MySQL Drivers in the Same ClasspathMariaDB Connector/J permits connection URLs beginning with both jdbc:mariadb and jdbc:mysql.However, if you also have MySQL's JDBC driver in your, then this could cause issues. To permit having MariaDB Connector/J and MySQL's JDBC driver in your at the same time, MariaDB Connector/J 1.5.9 and later do not accept connection URLs beginning with jdbc:mysql if the disableMariaDbDriver option is set in the connection URL.For example, the following connection URL would not be accepted by MariaDB Connector/J: jdbc:mysql://localhost:3306/db?user=someUser&disableMariaDbDriverThis allows you to have MariaDB Connector/J and MySQL's JDBC driver in your at the same time.
Using a PoolAnother way to get a connection with MariaDB Connector/J is to use a connection pool.MariaDB Connector/J provides 2 different Datasource pool implementations:. MariaDbDataSource: The basic implementation.
It creates a new connection each time the getConnection method is called. MariaDbPoolDataSource: A connection pool implementation. It maintains a pool of connections, and when a new connection is requested, one is borrowed from the pool.Internal PoolThe driver's internal pool configuration provides a very fast pool implementation and deals with the issues most of the java pool have:. 2 different connection states cleaning after release. deals with non-activity (connections in the pool will be released if not used after some time, avoiding the issue created when the server closes the connection after @waittimeout is reached).See the for more information. ModeDescriptionsequentialThis mode supports connection failover in a multi-master environment, such as MariaDB Galera Cluster. This mode does not support load-balancing reads on slaves.
The official MongoDB Java Driver providing both synchronous and asynchronous interaction with MongoDB. Features BSON Library A standalone BSON library, with a new Codec infrastructure that you can use to build high-performance encoders and decoders without requiring an. MariaDB Connector/J is used to connect applications developed in Java to MariaDB and MySQL databases using the standard JDBC API. The client library is.
The connector will try to connect to hosts in the order in which they were declared in the connection URL, so the first available host is used for all queries.For example, let's say that the connection URL is the following: jdbc:mariadb:sequential:host1,host2,host3/testdbWhen the connector tries to connect, it will always try host1 first. If that host is not available, then it will try host2. When a host fails, the connector will try to reconnect to hosts in the same order.This mode has been available sincefailoverThis mode supports connection failover in a multi-master environment, such as MariaDB Galera Cluster. This mode does not support load-balancing reads on slaves. The connector performs load-balancing for all queries by randomly picking a host from the connection URL for each connection, so queries will be load-balanced as a result of the connections getting randomly distributed across all hosts.For users migrating from MySQL Connector/J, this is equivalent to that driver's loadbalance mode.This mode has been available sincereplicationThis mode supports connection failover in a master-slave environment, such as a MariaDB Replication cluster. The mode supports environments with one or more masters. This mode does support load-balancing reads on slaves if the connection is set to read-only before executing the read.
The connector performs load-balancing by randomly picking a slave from the connection URL to execute read queries for a connection.This mode has been available sinceauroraThis mode supports connection failover in an Amazon Aurora cluster. This mode does support load-balancing reads on slave instances if the connection is set to read-only before executing the read. The connector performs load-balancing by randomly picking a slave instance to execute read queries for a connection.This mode has been available sinceSee for more information.Optional URL ParametersGeneral remark: Unknown options are accepted and silently ignored.The following options are currently supported. Essential Parameters. ParameterDescriptionuserDatabase user name.since 1.0.0passwordPassword of database user.since 1.0.0rewriteBatchedStatementsFor insert queries, rewrite batchedStatement to execute in a single executeQuery.example:insert into ab (i) values (?) with first batch values = 1, second = 2 will be rewritteninsert into ab (i) values (1), (2).If query cannot be rewriten in 'multi-values', rewrite will use multi-queries: INSERT INTO TABLE(col1) VALUES (?) ON DUPLICATE KEY UPDATE col2=? With values 1,2 and 2,3' will be rewrittenINSERT INTO TABLE(col1) VALUES (1) ON DUPLICATE KEY UPDATE col2=2; INSERT INTO TABLE(col1) VALUES (3) ON DUPLICATE KEY UPDATE col2=4when active, the useServerPrepStmts option is set to falseDefault: false. Since 1.1.8connectTimeoutThe connect timeout value, in milliseconds, or zero for no timeout.Default: 30 000.
Since 1.1.8useServerPrepStmtsPrepareStatement are prepared on the server side before executing. The applications that repeatedly use the same queries have value to activate this option, but the general case is to use the direct command (text protocol).if rewriteBatchedStatements is set to true, this option will be set to falseDefault: false (was true before 1.6.0). Since 1.3.0useBatchMultiSend.Not compatible with aurora.Driver will can send queries by batch.If set to false, queries are sent one by one, waiting for the result before sending the next one.If set to true, queries will be sent by batch corresponding to the useBatchMultiSendNumber option value (default 100) or according to the server variable if the packet size does not permit sending as many queries. Results will be read later, avoiding a lot of network latency when the client and server aren't on the same host.This option is mainly effective when the client is distant from the server. More informationDefault: true (false if using aurora failover). Since 1.5.0allowLocalInfilePermit loading data from file. See.Default: false.
Since 1.2.1useMysqlMetadatareturn 'MariaDB' or 'MySQL' according to server type (since 2.4.0). This option permit to force returning 'MySQL' even if server is MariaDB to permit compatibility with frameworks that doesn't support MariaDB.Default: false. Since 2.4.1TLS Parametersmore information on. ParameterDescriptionuseSSLForce.Default: false. Since 1.1.0trustServerCertificateWhen using SSL/TLS, do not check server's certificate.Default: false. Since 1.1.1serverSslCertPermits providing server's certificate in DER form, or server's CA certificate.
The server will be added to trustStor. ParameterDescriptionpoolUse pool. This option is useful only if not using a DataSource object, but only a connection object.Default: false. Since 2.2.0poolNamePool name that permits identifying threads.default: auto-generated as MariaDb-pool- since 2.2.0maxPoolSizeThe maximum number of physical connections that the pool should contain.Default: 8. Since 2.2.0minPoolSizeWhen connections are removed due to not being used for longer than than 'maxIdleTime', connections are closed and removed from the pool. 'minPoolSize' indicates the number of physical connections the pool should keep available at all times. Should be less or equal to maxPoolSize.Default: maxPoolSize value.
Since 2.2.0poolValidMinDelayWhen asking a connection to pool, the pool will validate the connection state. 'poolValidMinDelay' permits disabling this validation if the connection has been borrowed recently avoiding useless verifications in case of frequent reuse of connections. 0 means validation is done each time the connection is asked.Default: 1000 (in milliseconds). Since 2.2.0maxIdleTimeThe maximum amount of time in seconds that a connection can stay in the pool when not used. This value must always be below @waittimeout value - 45sDefault: 600 in seconds (=10 minutes), minimum value is 60 seconds. Since 2.2.0staticGlobalIndicates the values of the global variables, and ) won't be changed, permitting the pool to create new connections faster.Default: false. Since 2.2.0useResetConnectionWhen a connection is closed (given back to pool), the pool resets the connection state.
Setting this option, the prepare command will be deleted, session variables changed will be reset, and user variables will be destroyed when the server permits it (=, = MySQL 5.7.3), permitting saving memory on the server if the application make extensive use of variables. Must not be used with the useServerPrepStmts optionDefault: false.
Since 2.2.0registerJmxPoolRegister JMX monitoring pools.Default: true. Since 2.2.0Log Parameters.
ParameterDescriptionlogEnable log information.require Slf4j version 1.4 dependency.Log level correspond to Slf4j logging implementationDefault: false. Since 1.5.0maxQuerySizeToLogOnly the first characters corresponding to this options size will be displayed in logsDefault: 1024. Since 1.5.0slowQueryThresholdNanosWill log query with execution time superior to this value (if defined )Default: 1024. Since 1.5.0profileSqllog query execution time.Default: false. Since 1.5.0Infrequently Used Parameters. ParameterDescriptionpasswordCharacterEncodingIndicate password encoding charset.
Charset value must be a.Example: 'UTF-8'Default: null (= platform's default charset). Since 1.5.9useFractionalSecondsCorrectly handle subsecond precision in timestamps (feature available with and later).May confuse 3rd party components (Hibernated).Default: true. Since 1.0.0allowMultiQueriespermit multi-queries like insert into ab (i) values (1); insert into ab (i) values (2). Default: false. Since 1.0.0dumpQueriesOnExceptionIf set to 'true', an exception is thrown during query execution containing a query string.Default: false. Since 1.1.0useCompressionCompresses the exchange with the database through gzip. This permits better performance when the database is not in the same location.Default: false.
Since 1.0.0socketFactoryto use a custom socket factory, set it to the full name of the class that implements javax.net.SocketFactory.since 1.0.0tcpNoDelaySets corresponding option on the connection socket.since 1.0.0tcpKeepAliveSets corresponding option on the connection socket.since 1.0.0tcpAbortiveCloseThis option can be used in environments where connections are created and closed in rapid succession. Often, it is not possible to create a socket in such an environment after a while, since all local “ephemeral” ports are used up by TCP connections in TCPWAIT state. Using tcpAbortiveClose works around this problem by resetting TCP connections (abortive or hard close) rather than doing an orderly close.
It is accomplished by using socket.setSoLinger(true,0) for abortive close.since 1.1.1tcpRcvBufset buffer size for TCP buffer (SORCVBUF).since 1.0.0tcpSndBufset buffer size for TCP buffer (SOSNDBUF).since 1.0.0pipeOn Windows, specify named pipe name to connect to mysqld.exe.since 1.1.3tinyInt1isBitDatatype mapping flag, handle MySQL Tiny as BIT(boolean).Default: true. Since 1.0.0yearIsDateTypeYear is date type, rather than numerical.Default: true. If another query is executed on the same connection when a streaming resultset has not been fully read, the connector will put the whole remaining streaming resultset in memory in order to execute the next query. This can lead to OutOfMemoryError if not handled.Before version 1.4.0, the only accepted value for fetch size was Statement.setFetchSize(Integer.MINVALUE) (equivalent to Statement.setFetchSize(1)). This value is still accepted for compatilibity reasons but rather use Statement.setFetchSize(1), since according to JDBC the value must be = 0.
Prepared StatementsThe driver uses server prepared statements as a standard to communicate with the database (since 1.3.0). If the 'allowMultiQueries' or 'rewriteBatchedStatements' options are set to true, the driver will only use text protocol.
Prepared statements (parameter substitution) is handled by the driver, on the client side. CallableStatementCallable statement implementation won't need to access stored proceduremetadata table if both of following are true.
CallableStatement.getMetadata is not used. Parameters are accessed by index, not by nameWhen possible, following the two rules above provides both better speed andeliminates concerns about SELECT privileges on thetable. Optional JDBC ClassesThe following optional interfaces are implemented by theorg.mariadb.jdbc.MariaDbDataSource class: javax.sql.DataSource,javax.sql.ConnectionPoolDataSource, javax.sql.XADataSourcecareful: org.mariadb.jdbc.MySQLDataSource doesn't exist anymore and should be replaced with org.mariadb.jdbc.MariaDbDataSource since v1.3.0 Usage ExamplesThe following code provides a basic example of how to connect to a MariaDB orMySQL server and create a table.
Microsoft JDBC Driver for SQL Server. 2 minutes to read.In this articleIn our continued commitment to interoperability, Microsoft provides a Java Database Connectivity (JDBC) driver for use with SQL Server, and Azure SQL Database. The driver is available at no additional charge and provides Java database connectivity from any Java application, application server, or Java-enabled applet. This driver is a Type 4 JDBC driver that provides database connectivity through the standard JDBC application program interfaces (APIs).The Microsoft JDBC Driver for SQL Server has been tested against major application servers such as IBM WebSphere, and SAP NetWeaver. Getting started.Documentation.CommunityDownload- has additional information about Maven projects, and more.