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

查看:32
本文介绍了H2 的嵌入式数据库在哪里存储数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我最近才开始学习数据库是如何工作的,如何使用 SQL 等.并决定开始在我的 Java 应用程序(特别是 H2 数据库)中实现嵌入式数据库,并且似乎在我正在编写代码的计算机上运行良好.

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.

当我转移到另一台计算机继续我的编码时,我注意到即使我移植了嵌入式数据库文件 (h2-*.jar) 我在第一台计算机上创建的所有准备好的表都不存在于第二个.不知何故,我有一个先入之见,即通过数据库引擎生成的实际数据也存储在嵌入式数据库文件中.

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?

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

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.

谢谢!

推荐答案

阅读FAQ:

数据库文件存储在哪里?

Where are the Database Files Stored?

当使用像 jdbc:h2:~/test 这样的数据库 URL 时,数据库存储在用户目录中.对于 Windows,这通常是 C:Documents and SettingsC:Users.如果未设置基本目录(如jdbc:h2:./test),则数据库文件存储在应用程序启动的目录(当前工作目录)中.从开始菜单使用 H2 Console 应用程序时,这是 /bin.可以在数据库 URL 中设置基本目录.可以使用固定或相对路径.当使用 URL jdbc:h2:file:./data/sample 时,数据库存储在目录 data 中(相对于当前工作目录).如果该目录尚不存在,则会自动创建该目录.也可以使用完全限定的目录名称(对于 Windows,驱动器名称).示例:jdbc:h2:file:C:/data/test

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

这篇关于H2 的嵌入式数据库在哪里存储数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆