Embedding mysql in java desktop application

后端 未结 5 637
臣服心动
臣服心动 2020-12-03 15:25

i am not clear about steps/configuration details about how i can embed mysql in a Java desktop application so that it(application) can be installed on any machine through a

相关标签:
5条回答
  • 2020-12-03 15:55

    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....

    0 讨论(0)
  • 2020-12-03 16:01

    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.

    0 讨论(0)
  • 2020-12-03 16:05

    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?

    0 讨论(0)
  • 2020-12-03 16:12

    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.

    0 讨论(0)
  • 2020-12-03 16:12

    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.

    0 讨论(0)
提交回复
热议问题