H2'的嵌入式数据库在哪里存储数据?[英] Where does H2's Embedded Databases Store the data?

本文是小编为大家收集整理的关于H2'的嵌入式数据库在哪里存储数据?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

因此,我最近才开始学习数据库的工作方式,如何使用SQL ECT.并决定开始在我的Java应用程序(特别是H2数据库)中实现嵌入式数据库,并且似乎在我正在编码的计算机上工作得很好.

当我移动到另一台计算机继续我的编码时,我注意到即使我将嵌入式数据库文件(h2-*.jar)移植了我在第一台计算机中创建的所有准备好表第二个.我以某种方式有一个先入的看法,即通过数据库引擎生成的实际数据也存储在嵌入式数据库文件中.

所以我的问题是,数据库中的数据实际存储在哪里?是否可以准备一个已经包含数千个记录并使用实际应用程序进行分发的数据库?

我还应该提到,我在第一台计算机上连接到数据库的方式是通过JDBC连接,即url:jdbc:jdbc:h2:〜/test,当我尝试在第二台计算机上连接到该数据库时,不存在.

谢谢!

推荐答案

阅读 faq :

数据库文件存储在哪里?

使用jdbc:h2:~/test之类的数据库URL时,数据库存储在用户目录中.对于Windows,通常是C:\Documents and Settings\<userName>或C:\Users\<userName>.如果未设置基本目录(如jdbc:h2:./test中),则数据库文件存储在启动应用程序的目录中(当前工作目录).从开始菜单中使用H2控制台应用程序时,这是<Installation Directory>/bin.可以在数据库URL中设置基本目录.可以使用固定或相对路径.使用URL jdbc:h2:file:./data/sample时,数据库存储在目录数据中(相对于当前工作目录).如果目录尚不存在,则将自动创建该目录.也可以使用完全合格的目录名称(以及Windows,Drive名称).示例:jdbc:h2:file:C:/data/test

其他推荐答案

h2-*.jar只是数据库的引擎(代码).它是只读的,并且不存储任何信息. H2中的数据可以存储在指定文件中的内存或磁盘上.您实际上是在指定一个:

JDBC:h2:~/test/

您将在test子目录下的主目录中找到数据库.只需将这些文件复制到另一台计算机上的主目录,只要使用相同的URL即可找到它们.

其他推荐答案

在Windows中,您需要设置具有此值的JDBC URL:

JDBC URL: jdbc:h2:mem:testdb

本文地址:https://www.itbaoku.cn/post/597488.html

问题描述

So I just recently started learning about how databases work, how to use SQL ect. and decided to start implementing an embedded database into my Java application (specifically the H2 database) and seemed to work fairly well on the computer I was coding on.

When I moved over to a different computer to continue my coding I noticed that even if I ported the embedded database file (h2-*.jar) All of the prepared tables I created in the first computer don't exist on the second one. I somehow had the preconception that the actual data generated through the database engine are also stored in the embedded database file.

So my question is, where is the data from the database actually stored? is it possible to prepare a database which already contains thousands of records and distribute it with the actual application?

I should also mention that the way I connect to the database on the first computer was through a JDBC connection i.e. the URL: JDBC:h2:~/test and when I tried to connect to that database on the second computer it did not exist.

Thanks!

推荐答案

Read the FAQ:

Where are the Database Files Stored?

When using database URLs like jdbc:h2:~/test, the database is stored in the user directory. For Windows, this is usually C:\Documents and Settings\<userName> or C:\Users\<userName>. If the base directory is not set (as in jdbc:h2:./test), the database files are stored in the directory where the application is started (the current working directory). When using the H2 Console application from the start menu, this is <Installation Directory>/bin. The base directory can be set in the database URL. A fixed or relative path can be used. When using the URL jdbc:h2:file:./data/sample, the database is stored in the directory data (relative to the current working directory). The directory is created automatically if it does not yet exist. It is also possible to use the fully qualified directory name (and for Windows, drive name). Example: jdbc:h2:file:C:/data/test

其他推荐答案

The h2-*.jar is just an engine (the code) of the database. It is read-only and it does not store any information. The data in H2 can be stored either in memory or on disk in a specified file. You are actually specifying one:

JDBC:h2:~/test/

You'll find your database in your home directory under test subdirectory. Just copy these files to a home directory on another computer and H2 will find them as long as it uses the same URL.

其他推荐答案

In windows, you need to set JDBC URL with this value:

JDBC URL: jdbc:h2:mem:testdb