在 Java 桌面应用程序中嵌入 mysql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3393397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Embedding mysql in java desktop application
提问by Andrew
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 single executable file and doing so sets up database and also provides an exe to run the app.Till now i have built my app using netbeans and i have used mysql to set up database.plz guide me further.
我不清楚有关如何将 mysql 嵌入 Java 桌面应用程序的步骤/配置细节,以便它(应用程序)可以通过单个可执行文件安装在任何机器上,这样做会设置数据库并提供一个 exe 来运行应用程序。直到现在我已经使用 netbeans 构建了我的应用程序,并且我已经使用 mysql 来设置 database.plz 进一步指导我。
回答by OMG Ponies
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.
MySQL 不是嵌入式数据库——唯一与之相关的 JAR 是 JDBC 驱动程序。它需要一个安装过程,可能可以通过 Java 编写脚本,但该过程肯定会在您打算支持的 Java 应用程序之外运行。这意味着,您可以关闭 Java 应用程序,但 MySQL 服务/守护程序仍将运行。
Only the libmysqldis embeddable.
只有libmysqld是可嵌入的。
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....
有嵌入式数据库 - SQLite、Firebird - 和用 Java 制作的嵌入式数据库 - HSQL、Derby/(不记得以前叫什么了)。我相信 SQL Server Compact Edition 是可嵌入的,而 SQL Server Express/MSDE 则不是。不知道oracle有没有可嵌入的版本....
回答by Jay Askren
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.
我强烈推荐H2。它是一个用 Java 编写的非常快速的嵌入式数据库,我发现它比提到的其他一些数据库(例如 HSQL)更易于使用。
Edit:
编辑:
On the H2 website, you can see a speed comparison of H2 vs Derby, HSQL, MySql, etc...
在 H2 网站上,可以看到H2 与 Derby、HSQL、MySql等的速度比较...
回答by James Anderson
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.
虽然理论上可行,但这并不容易。标准的 MySql 发行版假设您要设置一个通用数据库服务器,与通过 odbc 等连接的客户端应用程序分开。
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".
您可能会更好地查看“纯 Java”选项,例如 HSQL 或 JavaDB,它们旨在嵌入 Java 应用程序中,并且几乎不需要“设置”。
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.
另一种可能性是 Sqlite,它只需要一个二进制文件加上 sqljbbc jar 文件。这又是从头开始设计的,嵌入在应用程序中,除了为数据库分配文件外,还需要零管理员。
回答by Adisesha
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.
看看http://dev.mysql.com/doc/refman/5.0/en/connector-mxj.html。我不记得确切的细节,但我能够在桌面应用程序中嵌入 MySQL 数据库,而无需用户单独安装它。
The key class is com.mysql.management.MysqldResource.
关键类是 com.mysql.management.MysqldResource。
Here is the example, http://dev.mysql.com/doc/refman/5.0/en/connector-mxj-configuration-java-object.html
这是示例,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.
mysql-connector-mxj-gpl-db-files.jar 文件包含所有平台的 MySQL 安装文件。如果您知道目标平台是哪个,则可以从 jar 中剥离其他平台版本,以减少最终用户的下载大小。
回答by Thorbj?rn Ravn Andersen
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.
如果您想要一个带有 Java 的嵌入式数据库,那么请使用一个用 Java 编写的嵌入式数据库。我知道 Apache Derby 可以嵌入并且显然也可以嵌入 H2。
How big amount of data dó you need the database to handle?
您需要数据库来处理多大的数据量?

