H2 的嵌入式数据库在哪里存储数据?

编程入门 行业动态 更新时间:2024-10-24 18:25:58
本文介绍了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 Settings 或 C: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 的嵌入式数据库在哪里存储数据?

本文发布于:2023-10-24 13:40:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524092.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌入式   数据库   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!