via: https://mariadb.com/kb/en/about-the-mariadb-java-client/
Introduction
The MariaDB Client Library for Java Applications is a Type 4 JDBC driver. It was developed specifically as a lightweight JDBC connector for use with MySQL and MariaDB database servers. It's originally based on the Drizzle JDBC code, and with a lot of additions and bug fixes.
Obtaining the driver
The driver (jar and source code) can be downloaded from https://downloads.mariadb.org/client-java/
Installing the driver
Installation is as simple as placing the .jar file in your classpath.
Requirements
- Java 6
- A MariaDB or MySQL Server
- maven (only if you want build from source)
Source code
The source code is available on Launchpad: https://launchpad.net/mariadb-java-client. Development version can be obtained using
bzr branch lp:mariadb-java-client
License
GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
Building and testing the driver
The section deals with building the connector from source and testing it. If you have downloaded a ready built connector, in a jar file, then this section may be skipped.
MariaDB Client Library for Java Applications uses maven for build. You first need to ensure you have both java and maven installed on your server before you can build the driver.
To run the unit test, you'll need a MariaDB or MySQL server running on localhost (on default TCP port 3306) and a database called 'test', and user 'root' with empty password
$ bzr branch lp:mariadb-java-client # Or, unpack the source distribution tarball $ cd mariadb-java-client # For the unit test run, start local mysqld mysqld, # ensure that user root with empty password can login $ mvn package # If you want to build without running unit tests, use # mvn -Dmaven.test.skip=true package
After that , you should have JDBC jar mariadb-java-client-x.y.z.jar in the 'target' subdirectory
Installing the driver
Installation of the client library is very simple, the jar file should be saved in an appropriate place for your application and the classpath of your application altered to include the MariaDB Client Library for Java Applications rather than your current connector.
Using the driver
The following subsections show the formatting of JDBC connection strings for MariaDB, MySQL database servers. Additionally, sample code is provided that demonstrates how to connect to one of these servers and create a table.
Driver Manager
Applications designed to use the driver manager to locate the entry point need no further configuration, the MariaDB Client Library for Java Applications will automatically be loaded and used in the way any previous MySQL driver would have been.
Driver Class
Please note that the driver class provided by the MariaDB Client Library for Java Applications is notcom.mysql.jdbc.Driver
but org.mariadb.jdbc.Driver
!
Connection strings
Format of the JDBC connection string is
jdbc:mysql://<host>:<port>/<database>?<key1>=<value1>&<key2>=<value2>...
Altenatively
jdbc:mariadb://<host>:<port>/<database>?<key1>=<value1>&<key2>=<value2>...
can also be used.
what't more,for cluster,it should be like this, jdbc:mariadb://<host1>:<port1>,<host2>:<port2>/<database>?<key1>=<value1>&<key2>=<value2>...
Optional URL parameters
General remark: Unknown options accepted and are silently ignored.
Following options are currently supported.
user | Database user name | 1.0.0 |
password | Password of database user | 1.0.0 |
fastConnect | If set, skips check for sql_mode, assumes NO_BACKSLASH_ESCAPES is *not* set | 1.0.0 |
useFractionalSeconds | Correctly handle subsecond precision in timestamps (feature available with MariaDB 5.3 and later).May confuse 3rd party components (Hibernated) | 1.0.0 |
allowMultiQueries | Allows multiple statements in single executeQuery | 1.0.0 |
dumpQueriesOnException | If set to 'true', exception thrown during query execution contain query string | 1.1.0 |
useCompression | allow compression in MySQL Protocol | 1.0.0 |
useSSL | Force SSL on connection | 1.1.0 |
trustServerCertificate | When using SSL, do not check server's certificate | 1.1.1 |
serverSslCert | Server's certificatem in DER form, or server's CA certificate. Can be used in one of 3 forms, sslServerCert=/path/to/cert.pem (full path to certificate), sslServerCert=classpath:relative/cert.pem (relative to current classpath), or as verbatim DER-encoded certificate string "------BEGING CERTIFICATE-----" | 1.1.3 |
socketFactory | to use custom socket factory, set it to full name of the class that implements javax.net.SocketFactory | 1.0.0 |
tcpNoDelay | Sets corresponding option on the connection socket | 1.0.0 |
tcpKeepAlive | Sets corresponding option on the connection socket | 1.0.0 |
tcpAbortiveClose | Sets corresponding option on the connection socket | 1.1.1 |
tcpRcvBuf | set buffer size for TCP buffer (SO_RCVBUF) | 1.0.0 |
tcpSndBuf | set buffer size for TCP buffer (SO_SNDBUF) | 1.0.0 |
pipe | On Windows, specify named pipe name to connect to mysqld.exe | 1.1.3 |
tinyInt1isBit | Datatype mapping flag, handle MySQL Tiny as BIT(boolean) | 1.0.0 |
yearIsDateType | Year is date type, rather than numerical | 1.0.0 |
sessionVariables | <var>=<value> pairs separated by comma, mysql session variables, set upon establishing successfull connection | 1.1.0 |
localSocket | Allows to connect to database via Unix domain socket, if server allows it. The value is the path of Unix domain socket, i.e "socket" database parameter | 1.1.4 |
sharedMemory | Allowed to connect database via shared memory, if server allows it. The value is base name of the shared memory | 1.1.4 |
JDBC API Implementation Notes
Streaming result sets
By default, Statement.executeQuery()
will read full result set from server before returning. With large result sets, this will require large amounts of memory. Better behavior in this case would be reading row-by-row, with ResultSet.next()
, so called "streaming" feature. It is activated using Statement.setFetchSize(Integer.MIN_VALUE)
Prepared statements
The driver only uses text protocol to communicate with the database. Prepared statements (parameter substitution) is handled by the driver, on the client side.
CallableStatement
Callable statement implementation won't need to access stored procedure metadata ( mysql.proc) table, if both of following is true
- CallableStatement.getMetadata() is not used
- Parameters are accessed by index, not by name
When possible, following 2 rules above provides both better speed and eliminates concerns about SELECT privileges on mysql.proc table
Optional JDBC classes
Following optional interfaces are implemented by the org.mariadb.jdbc.MySQLDataSource class : javax.sql.DataSource, javax.sql.ConnectionPoolDataSource, javax.sql.XADataSource
Usage examples
The following code provides a basic example of how to connect to a MariaDB or MySQL server and create a table.
Creating a table on a MariaDB or MySQL Server
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "username", "password"); Statement stmt = connection.createStatement(); stmt.executeUpdate("CREATE TABLE a (id int not null primary key, value varchar(20))"); stmt.close(); connection.close();
相关推荐
navicat150_mariadb_cs_x64.exe 一款专门为mariadb 数据库使用的navicat工具
标题"Mariadb_install_win.rar"表明这是一个关于在Windows操作系统上安装MariaDB的压缩包文件,特别是通过批处理(BAT)脚本来实现一键安装的过程。MariaDB是一个开源的关系型数据库管理系统,它是MySQL的一个分支,...
(34条消息) CentOS 7 安装mariadb_centos7安装mariadb_托塔雨天王的博客-CSDN博客.mhtml
Centos7自动安装mariadb并设置密码允许用户远程登录脚本
Automatic_installation_for_MariaDB_on_Linux(MariaD_ansible-mariadb
标题中的"navicat110_mariadb_cs_x86.zip"指向的是一款专为32位Windows系统设计的Navicat for MariaDB的11.0版本。这款工具以其直观的界面和强大的功能,让数据库管理变得轻松而高效。 首先,Navicat for MariaDB是...
本文将详细介绍如何使用提供的shell脚本"Mariadb_install_linux"在CentOS 7上进行MariaDB的安装。MariaDB是MySQL的一个分支,由MySQL的创始人创建,旨在保持开源和不受Oracle公司控制。 1. **CentOS 7系统准备**: ...
mariadb_10.0.14 龙芯cpu 安装包,已经适配了3A3000,3a4000. 安装后需要命令好启动。 安装路径为\usr\local\mysql。 仅供研究使用,请勿商用。
MariaDB数据库驱动包
这个“mariadb_v10.5.8_winx64_itmop.com.zip”压缩包包含了在Windows 64位系统上运行的MariaDB 10.5.8版本。 MariaDB 10.5.8是该数据库系统的一个重要版本,提供了许多新特性和改进。以下是一些关键知识点: 1. *...
MariaDB数据库驱动包
mariadb-java-client-2.4.0.jar和mysql-connector-java-8.0.11.jar驱动 驱动信息。mm-mysql-2.0.13-bin.jar 这些jar包都可以驱动
用于MariaDB的Navicat为MariaDB数据库管理和开发提供了本机环境。连接到本地/远程MariaDB服务器,并与Amazon RDS兼容。适用于MariaDB的Navicat支持大多数附加功能,例如新的存储引擎,微秒,虚拟列等。
VERITAS NetBackup 8.2 中文管理指南是 Veritas Technologies LLC 发布的一份关于 VERITAS NetBackup for MariaDB 的管理指南,该指南适用于 Windows 和 Linux 平台,版本为 8.2。本指南最后一次更新时间为 2019 年 ...
MariaDB数据库驱动包
mariadb-java-client-1.3.3.jar mariadb-java-client-1.3.3-sources.jar mariadb-java-client-1.3.3-javadoc.jar mariadb-java-client-1.3.3.tar.gz 我从官方下载的,地址为:...
MariaDB数据库驱动包
A simple tool, which can help you bring all data stored in Excel Data Files into MariaDB, and then you can handle your data in MariaDB via this tool through Excel. Just try it!
Veritas NetBackup 8.1.2 是一款强大的数据保护解决方案,特别针对MariaDB数据库管理系统设计的管理员指南。本指南提供了在Windows和Linux操作系统上管理MariaDB备份的详细信息,帮助用户确保数据的安全性和可恢复性...