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

标签 java database jdbc h2 embedded-database

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

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

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

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

谢谢!

最佳答案

阅读 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

关于java - H2 的嵌入式数据库在哪里存储数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9461770/

相关文章:

java - 检测postgresql中的数据变化

android cursor.moveToNext()?

java - 与存储在不同计算机上的MS Server连接的JDBC程序

java - 如何使用mysql在java中执行result.beforeFirst后使用resultset.next方法

java - Android tcp套接字设置etimedout值

java - 为什么 if 语句总是返回 false

Java:扫描仪初学者

java - 我们如何从基类中检索接口(interface)并测试它?

mysql - 加快返回许多结果的 mysql 查询

jdbc - 使用 JDBC 和 Clojure 访问大型数据集的有效方法是什么