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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43470295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:25:09  来源:igfitidea点击:

How to store H2 database file into project directory

javasqldatabaseeclipseh2

提问by Armer B.

When I used H2 database the database files are stored at C:\Users\MyName\TestDataBase.dbdirectory. The H2 path is jdbc:h2:~/TestDataBase. This is default H2 database path.

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

Is there a possibility to store H2 database file into my project directory like this C:\Users\MyName\EclipseWorkspace\ProjectName\TestDataBase.dband how to config path to do this?

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

回答by fiskra

If you have h2 console you can basically create a new db wherever you want. If you read carefully h2 faq, they described very well how you can do that.

如果你有 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

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

h2 faq

h2 常见问题

So just set your jdbc url to : jdbc:h2:file:C:/Users/MyName/EclipseWorkspace/ProjectName/TestDataBase

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