MariaDB is "a backward compatible, drop-in replacement of the MySQL(R) Database Server" :
- Homepage: http://mariadb.org
- FAQ: http://kb.askmonty.org/en/mariadb-faq
- Wikipedia: http://en.wikipedia.org/wiki/MariaDB
MariaDB4j is a Java "launcher" for MariaDB, allowing to use it from Java without ANY installation / external dependencies. Read again: You do NOT have to have MariaDB binaries installed on your system to use MariaDB4j!
MariaDB binaries are in the MariaDB4j JAR and, by default, extracted to a temporary base directory on the fly, then started by Java:
- Install the database with a particular configuration, using short-cut:
DB db = DB.newEmbeddedDB(3306);
- (Optional) The data directory will, by default, be in a temporary directory too, and will automatically get scratched at every restart; this is suitable for integration tests. If you use MariaDB4j for something more permanent (maybe an all-in-one application package?), then you can simply specify a more durable location of your data directory in the Configuration, like so:
Configuration config = new Configuration();
config.setPort(3306);
// OR: config.detectFreePort(); // == config.setPort(0);
config.setDataDir("/home/theapp/db"); // just an example
DB db = DB.newEmbeddedDB(config);
- Start the database
db.start();
- Use the database
Connection conn = db.getConnection();
or: Use your your favourite connection pool... business as usual.
- If desired, load data from a SQL resource
db.source("path/to/resource.sql");
MariaDB4j is not in Maven central (yet; it could be if you asked for it...), so for now you (or your build server) have to build it yourself from source. -- MariaDB4j's Maven coordinates are:
<groupId>ch.vorburger.mariaDB4j</groupId>
<artifactId>mariaDB4j</artifactId>
<version>1.0.0</version>
Being able to start a database without any installation / external dependencies is useful in a number of scenarios, such as all-in-one application packages, or for running integration tests without depending on the installation, set-up and up-and-running of an externally managed server. You could also use this easily run some DB integration tests in parallel but completely isolated, as the MariaDB4j API explicitly support this.
Java developers frequently use pure Java databases such as H2, hsqldb (HyperSQL), Derby / JavaDB for this purpose. This library brings the advantage of the installation-free DB approach, while maintaining MariaDB (and thus MySQL) compatibility.
It was initially developed for use in Mifos, the "Open Source Technology that accelerates Microfinance", see http://mifos.org.
- Michael Vorburger, February/March 2012.
- Michael Seaton, October 2013.
- Juhani Simola, March 2014.
- YourNameHere, if you jump on-board...
Contributions, patches, forks more than welcome - hack it, and add your name here! ;-)