Embedding mysql in java desktop application

蓝咒 提交于 2019-11-28 09:59:35

MySQL isn't an embedded database - the only JAR related to it is the JDBC driver. It requires a installation process, which might be able to be scripted via Java, but the process will definitely function outside of the Java application you intend it to support. Meaning, you can turn off your Java application but the MySQL service/daemon will still be running.

Only the libmysqld is embeddable.

There are embedded databases - SQLite, Firebird - and embedded databases made in Java - HSQL, Derby/(can't remember what it was called before). I believe SQL Server Compact Edition is embeddable, while SQL Server Express/MSDE is not. I don't know if Oracle has an embeddable version....

I would strongly recommend H2. It is a very fast embedded database written in Java and I've found it easier to use than some of the others mentioned such as HSQL.

Edit:

On the H2 website, you can see a speed comparison of H2 vs Derby, HSQL, MySql, etc...

Here's information on how to backup the database.

While theoritcaly possable it would not be easy. The standard MySql distributions assume you want to set up a general purpose database server with separate from the client applications cominicating via odbc etc.

You may be better looking at the "pure java" options like HSQL or JavaDB which are designed to be embedded in a java application, and need little or no "setup".

Another possibility is Sqlite which only needs a single binary plus the sqljbbc jar file. This is again designed from scratch to be embedded inside an application and requires zero admin apart from allocating a file for the database.

Take a look at http://dev.mysql.com/doc/refman/5.0/en/connector-mxj.html. I do not remember the exact details but I was able to embed MySQL db in desktop application without user needing to install it separately.

The key class is com.mysql.management.MysqldResource.

Here is the example, http://dev.mysql.com/doc/refman/5.0/en/connector-mxj-configuration-java-object.html

The mysql-connector-mxj-gpl-db-files.jar file contains MySQL installation files for all the platforms. If you know which is your target platform, you can strip other platform versions from jar, to reduce download size for end user.

If you want an embedded database with java, then use one written in Java designed to be embedded. I know Apache Derby Can be embedded and apparently H2 too.

How big amount of data dó you need the database to handle?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!