使用 Java SE 应用程序轻松部署数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4429294/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:19:43  来源:igfitidea点击:

Easy database to deploy with a Java SE application

javadatabaseapi

提问by fredcrs

I have a Java SE application, and it uses a database. I am currently using XML files to store data, but I′m afraid it causes some errors in later use.

我有一个 Java SE 应用程序,它使用一个数据库。我目前使用XML文件来存储数据,但我担心在以后的使用中会出现一些错误。

So it would be good to use a Postgree/MySQL like DB. A real database. but the problem is, it is a commercial application, it runs under windows, and should be 2 clicks to install. I really don't like the idea of installing a database together with my application, and then running scripts to build the tables.

所以最好使用像 DB 这样的 Postgree/MySQL。一个真正的数据库。但问题是,它是一个商业应用程序,它在windows下运行,应该是2次点击安装。我真的不喜欢将数据库与我的应用程序一起安装,然后运行脚本来构建表的想法。

Is there a database that I can use as a Java API? Or should I just continue to use XML? (I'm synchronizing every access to my XML files). Whats the best choice?

是否有可以用作 Java API 的数据库?还是我应该继续使用 XML?(我正在同步对我的 XML 文件的每次访问)。最好的选择是什么?

回答by darioo

One of following embedded databases:

以下嵌入式数据库之一:

They are lightweight, take up very little space and can be embedded without problems in your application.

它们重量轻,占用的空间很小,可以毫无问题地嵌入到您的应用程序中。

Since they are written in Java, and each one is a simple jar file, your deployment headaches will be kept to a minimum.

由于它们是用 Java 编写的,并且每个都是一个简单的 jar 文件,因此您的部署麻烦将降至最低。

You've mentioned MySQL and PostgreSQL. Although I haven't tried it, H2 features several compatibility modesfor various popular databases, including ones you've mentioned.

你提到了 MySQL 和 PostgreSQL。虽然我没有尝试过,但 H2为各种流行的数据库提供了几种兼容模式,包括你提到的那些。

回答by willcodejavaforfood

H2 Database

H2数据库

It can be embedded in your application with no clicks to install and it supports JDBC and most ORMs.

它可以嵌入到您的应用程序中,无需单击即可安装,并且支持 JDBC 和大多数 ORM。

回答by Christian Stade-Schuldt

It is definitely worth to look for a simple SQLite database as the storage. It is just a single file on your file system. No need to set up a server. Check out the following thread for an introduction: Java and SQLiteAnother database you could check out is HSQLDB (link inside another answer inside this thread). That one is a relational database engine written in Java also based on a single file.

寻找一个简单的 SQLite 数据库作为存储绝对值得。它只是文件系统上的一个文件。无需设置服务器。查看以下线程的介绍:Java 和 SQLite您可以查看的另一个数据库是 HSQLDB(此线程内的另一个答案中的链接)。那是一个用 Java 编写的关系数据库引擎,也基于单个文件。

回答by mauris

Based on my previous naive experience of storing data into XML, I wrote a entire forum system on XML and it's based on RSS parser and writer. The XML files became very big and thus causing frequent request time outs on the application.

根据我以前将数据存储到 XML 的幼稚经验,我在 XML 上编写了一个完整的论坛系统,它基于 RSS 解析器和编写器。XML 文件变得非常大,从而导致应用程序的频繁请求超时。

You can instead use something like SQLite, where data is stored in a file but more managed and allows declarative statements like SELECT * FROM table.

您可以改用 SQLite 之类的东西,其中数据存储在文件中,但受到更多管理,并允许声明性语句,例如SELECT * FROM table.