gpt4 book ai didi

java - 如何将H2数据库文件存储到项目目录中

转载 作者:搜寻专家 更新时间:2023-10-30 19:57:30 24 4
gpt4 key购买 nike

当我使用 H2 数据库时,数据库文件存储在 C:\Users\MyName\TestDataBase.db 目录中。 H2 路径是 jdbc:h2:~/TestDataBase。这是默认的 H2 数据库路径。

是否有可能像这样将 H2 数据库文件存储到我的项目目录中 C:\Users\MyName\EclipseWorkspace\ProjectName\TestDataBase.db 以及如何配置路径来执行此操作?

最佳答案

如果你有 h2 控制台,你基本上可以在任何你想要的地方创建一个新的数据库。如果您仔细阅读 h2 常见问题解答,他们会很好地描述您如何做到这一点。

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\ or C:\Users\. 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 /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 faq

所以只需将您的 jdbc url 设置为:jdbc:h2:file:C:/Users/MyName/EclipseWorkspace/ProjectName/TestDataBase

关于java - 如何将H2数据库文件存储到项目目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43470295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com