MariaDB_About the MariaDB Java Client
来源:互联网 发布:健身书籍知乎 编辑:程序博客网 时间:2024/06/06 07:04
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.
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();
- MariaDB_About the MariaDB Java Client
- About the MariaDB Java Client
- The Java EE 6 Tutorial Maintaining Client State
- java client
- Writing the RPC Client
- The Client hold the Interface
- java连接mariaDB的设置
- Java连接MariaDB数据库代码
- Configuring the JA-SIG CAS Client for Java in the web.xml
- mariaDB
- MariaDB
- MariaDB
- mariaDB
- Mariadb
- mariadb
- mariadb
- mariadb
- Mariadb
- Thinking in Java 学习笔记1 数组
- HashMap和Hashtable的区别
- Java 基础【05】你的多继承纳?
- Eclipse_JD-Eclipse plugin
- unity3D序列化参数可以设置枚举的方法
- MariaDB_About the MariaDB Java Client
- 初学编程——编程练习
- MariaDB_Setting Character Sets and Collations
- DUBBO分布式服务框架与SpringMVC+Zookeeper实现服务提供和消费
- Linux 安装openmpi
- Retrofit+Rxjava问题
- 欢迎使用CSDN-markdown编辑器
- Struts2_基于注解的Action配置
- Caffe+Anconda3+VS2015+Win10(64位)环境搭建