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();
相关推荐
首先,我们需要访问MariaDB的官方网站 (<https://mariadb.org/about/>) 下载适合的安装包。下载完成后,你会得到一个压缩文件,解压到你选择的目录。在解压目录中,你会发现三个配置文件:my-large、my-medium和my-...
This book shows you how to build fast, efficient, and scalable client-server solutions using the latest versions of Node. The book begins with debugging tips and tricks of the trade, and how to write...
嵌入式八股文面试题库资料知识宝典-华为的面试试题.zip
训练导控系统设计.pdf
嵌入式八股文面试题库资料知识宝典-网络编程.zip
人脸转正GAN模型的高效压缩.pdf
少儿编程scratch项目源代码文件案例素材-几何冲刺 转瞬即逝.zip
少儿编程scratch项目源代码文件案例素材-鸡蛋.zip
嵌入式系统_USB设备枚举与HID通信_CH559单片机USB主机键盘鼠标复合设备控制_基于CH559单片机的USB主机模式设备枚举与键盘鼠标数据收发系统支持复合设备识别与HID
嵌入式八股文面试题库资料知识宝典-linux常见面试题.zip
面向智慧工地的压力机在线数据的预警应用开发.pdf
基于Unity3D的鱼类运动行为可视化研究.pdf
少儿编程scratch项目源代码文件案例素材-霍格沃茨魔法学校.zip
少儿编程scratch项目源代码文件案例素材-金币冲刺.zip
内容概要:本文深入探讨了HarmonyOS编译构建子系统的作用及其技术细节。作为鸿蒙操作系统背后的关键技术之一,编译构建子系统通过GN和Ninja工具实现了高效的源代码到机器代码的转换,确保了系统的稳定性和性能优化。该系统不仅支持多系统版本构建、芯片厂商定制,还具备强大的调试与维护能力。其高效编译速度、灵活性和可扩展性使其在华为设备和其他智能终端中发挥了重要作用。文章还比较了HarmonyOS编译构建子系统与安卓和iOS编译系统的异同,并展望了其未来的发展趋势和技术演进方向。; 适合人群:对操作系统底层技术感兴趣的开发者、工程师和技术爱好者。; 使用场景及目标:①了解HarmonyOS编译构建子系统的基本概念和工作原理;②掌握其在不同设备上的应用和优化策略;③对比HarmonyOS与安卓、iOS编译系统的差异;④探索其未来发展方向和技术演进路径。; 其他说明:本文详细介绍了HarmonyOS编译构建子系统的架构设计、核心功能和实际应用案例,强调了其在万物互联时代的重要性和潜力。阅读时建议重点关注编译构建子系统的独特优势及其对鸿蒙生态系统的深远影响。
嵌入式八股文面试题库资料知识宝典-奇虎360 2015校园招聘C++研发工程师笔试题.zip
嵌入式八股文面试题库资料知识宝典-腾讯2014校园招聘C语言笔试题(附答案).zip
双种群变异策略改进RWCE算法优化换热网络.pdf
内容概要:本文详细介绍了基于瞬时无功功率理论的三电平有源电力滤波器(APF)仿真研究。主要内容涵盖并联型APF的工作原理、三相三电平NPC结构、谐波检测方法(ipiq)、双闭环控制策略(电压外环+电流内环PI控制)以及SVPWM矢量调制技术。仿真结果显示,在APF投入前后,电网电流THD从21.9%降至3.77%,显著提高了电能质量。 适用人群:从事电力系统研究、电力电子技术开发的专业人士,尤其是对有源电力滤波器及其仿真感兴趣的工程师和技术人员。 使用场景及目标:适用于需要解决电力系统中谐波污染和无功补偿问题的研究项目。目标是通过仿真验证APF的有效性和可行性,优化电力系统的电能质量。 其他说明:文中提到的仿真模型涉及多个关键模块,如三相交流电压模块、非线性负载、信号采集模块、LC滤波器模块等,这些模块的设计和协同工作对于实现良好的谐波抑制和无功补偿至关重要。
内容概要:本文探讨了在工业自动化和物联网交汇背景下,构建OPC DA转MQTT网关软件的需求及其具体实现方法。文中详细介绍了如何利用Python编程语言及相关库(如OpenOPC用于读取OPC DA数据,paho-mqtt用于MQTT消息传递),完成从OPC DA数据解析、格式转换到最终通过MQTT协议发布数据的关键步骤。此外,还讨论了针对不良网络环境下数据传输优化措施以及后续测试验证过程。 适合人群:从事工业自动化系统集成、物联网项目开发的技术人员,特别是那些希望提升跨协议数据交换能力的专业人士。 使用场景及目标:适用于需要在不同通信协议间建立高效稳定的数据通道的应用场合,比如制造业生产线监控、远程设备管理等。主要目的是克服传统有线网络限制,实现在不稳定无线网络条件下仍能保持良好性能的数据传输。 其他说明:文中提供了具体的代码片段帮助理解整个流程,并强调了实际部署过程中可能遇到的问题及解决方案。