除了 mysql、sql 等数据库之外的存储数据的替代方案
我已经在Java核心中完成了我的项目地址簿,其中我的数据存储在数据库(MySql)中。
我面临一个问题,当我在其他计算机上运行程序时,需要再次创建孔数据库。
所以请告诉我在不使用任何数据库软件(如 mysql、sql 等)的情况下存储数据的任何替代方案。
I had completed my project Address Book in Java core, in which my data is stored in database (MySql).
I am facing a problem that when i run my program on other computer than tere is the requirement of creating the hole data base again.
So please tell me any alternative for storing my data without using any database software like mysql, sql etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您可以使用内存数据库,例如 HSQLDB、Derby(又名 JavaDB) , H2, ..
所有这些都可以运行,无需安装任何额外的软件,并且可以就像另一个图书馆一样。
You can use an in-memory database such as HSQLDB, Derby (a.k.a JavaDB), H2, ..
All of those can run without any additional software installation and can be made to act like just another library.
我建议使用可嵌入的轻量级数据库,例如 SQLite。一探究竟。
从功能页面(在SQLite的建议用途部分下):
I would suggest using an embeddable, lightweight database such as SQLite. Check it out.
From the features page (under the section Suggested Uses For SQLite):
StackOverflow 的全部意义在于,您不必通过电子邮件发送问题/答案:)
您可以将数据存储在文件系统、内存(使用序列化等)中,这些是数据库的简单替代品。您甚至可以使用完全在内存中运行的 HSQLDB
The whole point of StackOverflow was so that you would not have to email around questions/answers :)
You could store data in a filesystem, memory (use serialisation etc) which are simple alternatives to DB. You can even use HSQLDB which can be run completely in memory
如果你的数据不是很大,你可以使用简单的txt文件并将所有内容存储在其中。然后加载到内存中。但这将导致改变您修改/查询数据的方式。
If you data is not so big, you may use simple txt file and store everything in it. Then load it in memory. But this will lead to changing the way you modify/query data.
mysql、sql 等数据库软件提供了实施工作方面的抽象。如果您希望避免使用相同的数据库,您可以考虑拥有自己的数据库,例如 XML 或平面文件。 XML 仍然是更好的选择,因为 XML 解析器或处理程序可用。从长远来看,将数据放入自定义数据库/平面文件中将无法管理。
你为什么不探索sqlite呢?它是基于文件的,意味着您不需要单独安装它,并且您仍然拥有标准 SQL 来检索数据或与数据交互?我认为,sqlite 将是一个更好的选择。
Database software like mysql, sql etc provides an abstraction in terms of implementation effort. If you wish to avoid using the same, you can think of having your own database like XML or flat files. XML is still a better choice as XML parsers or handlers are available. Putting your data in your customised database/flat files will not be manageable in the long run.
Why don't you explore sqlite? It is file based, means you don't need to install it separately and still you have the standard SQL to retrieve or interact with the data? I think, sqlite will be a better choice.
只需使用 prevayler (.org)。比使用数据库更快、更简单。
Just use a prevayler (.org). Faster and simpler than using a database.
根据您的问题,我假设您希望将某种形式的持久存储存储到运行应用程序的计算机的本地文件系统中。除此之外,您还需要决定如何使用应用程序中的数据及其数量。您需要数据库吗?您要搜索不同字段的数据吗?您需要查询语言吗?数据是否足够小以适合内存中的简单数据结构?它需要有多大的弹性?这些类型问题的答案将有助于正确选择存储。您可能只需要一个简单的 CSV 文件、XML 或类似文件。有许多轻量级数据库,例如 SQLite、Berkelely DB、JavaDB 等 - 但您是否需要数据库的强大功能取决于您的要求。
I assume from your question that you want some form of persistent storage to the local file system of the machine your application runs on. In addition to that, you need to decide on how the data in your application is to be used, and the volume of it. Do you need a database? Are you going to be searching the data different fields? Do you need a query language? Is the data small enough to fit in to a simple data structure in memory? How resilient does it need to be? The answers to these types of questions will help lead to the correct choice of storage. It could be that all you need is a simple CSV file, XML or similar. There are a host of lightweight databases such as SQLite, Berkelely DB, JavaDB etc - but whether or not you need the power of a database is up to your requirements.
我最近经常使用的商店是 Neo4j。它是一个图形数据库,不仅易于使用,而且完全用 Java 编写并嵌入。与 SQL 替代方案相比,我更喜欢它。
A store that I'm using a lot these days is Neo4j. It's a graph database and is not only easy to use but also is completely in Java and is embedded. I much prefer it to a SQL alternative.
除了有关嵌入式数据库的其他答案之外,我还在开发一个对象数据库,它可以直接序列化 java 对象,而不需要 ORM。它的名字是 Sofof 我在我的项目中使用它。它有许多功能,在其网站页面中有描述。
In addition of the others answers about embedded databases I was working on a objects database that directly serialize java objects without the need for ORM. Its name is Sofof and I use it in my projects. It has many features which are described in its website page.