在java桌面应用程序中嵌入mysql
我不清楚如何在 Java 桌面应用程序中嵌入 mysql 的步骤/配置细节,以便它(应用程序)可以通过单个可执行文件安装在任何计算机上,这样做会设置数据库并提供一个 exe 来运行应用程序。到目前为止,我已经使用 netbeans 构建了我的应用程序,并且使用 mysql 来设置数据库。请进一步指导我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
MySQL 不是嵌入式数据库 - 与其相关的唯一 JAR 是 JDBC 驱动程序。它需要一个安装过程,可以通过 Java 编写脚本,但该过程肯定会在您希望它支持的 Java 应用程序之外运行。这意味着,您可以关闭 Java 应用程序,但 MySQL 服务/守护进程仍将运行。
只有 libmysqld 是可嵌入的。
有嵌入式数据库 - SQLite、Firebird - 以及用 Java 制作的嵌入式数据库 - HSQL、Derby/(不记得以前叫什么了)。我相信 SQL Server Compact Edition 是可嵌入的,而 SQL Server Express/MSDE 则不是。不知道Oracle有没有嵌入式版本....
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....
我强烈推荐 H2。它是一个用 Java 编写的非常快的嵌入式数据库,我发现它比提到的其他一些数据库(例如 HSQL)更容易使用。
编辑:
在H2网站上,您可以看到H2的速度比较与 Derby、HSQL、MySql 等...
这里是有关如何备份数据库的信息。
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.
虽然理论上可行,但这并不容易。标准 MySql 发行版假设您想要设置一个通用数据库服务器,与通过 odbc 等进行通信的客户端应用程序分开。
您可能最好查看“纯 java”选项,例如 HSQL 或 JavaDB,它们被设计为嵌入到java 应用程序,并且需要很少或不需要“设置”。
另一种可能性是 Sqlite,它只需要一个二进制文件加上 sqljbbc jar 文件。这又是从头开始设计的,可以嵌入到应用程序中,除了为数据库分配文件之外,还需要零管理。
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.
看看 http://dev.mysql.com/ doc/refman/5.0/en/connector-mxj.html。我不记得确切的细节,但我能够将 MySQL 数据库嵌入到桌面应用程序中,而无需用户单独安装它。
关键类是com.mysql.management.MysqldResource。
这是示例, http:// /dev.mysql.com/doc/refman/5.0/en/connector-mxj-configuration-java-object.html
mysql-connector-mxj-gpl-db-files.jar 文件包含 MySQL 安装文件所有平台。如果您知道哪个是您的目标平台,您可以从 jar 中剥离其他平台版本,以减少最终用户的下载大小。
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.
如果您想要一个带有 java 的嵌入式数据库,那么使用一个用 Java 编写的嵌入式数据库。我知道 Apache Derby 可以嵌入,显然 H2 也可以。
您需要数据库处理多少数据?
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?