所以我刚刚开始学习数据库如何工作,如何使用SQL ect。并决定开始在我的Java应用程序(特别是H2数据库)中实现一个嵌入式数据库,并且似乎在编码的计算机上运行良好。
到不同的计算机以继续我的编码我注意到,即使我移植嵌入式数据库文件(h2 - *。jar)我在第一台计算机中创建的所有准备表不存在第二个。我不知何故有一个先入之见,通过数据库引擎生成的实际数据也存储在嵌入的数据库文件中。
所以我的问题是,数据从哪里来实际存储?是否有可能准备一个已经包含数千条记录并将其与实际应用程序一起分发的数据库?
我还应该提到我连接到第一台计算机上的数据库的方式是通过JDBC连接,即URL:JDBC:h2:〜/ test,尝试连接到第二台计算机上不存在的数据库。
谢谢!
解决方案阅读常见问题:
数据库文件存储在哪里?
使用 jdbc :h2:〜/ test ,数据库存储在用户目录中。对于Windows,这通常是 C:\Documents和Settings\< userName> 。如果未设置基本目录(如 jdbc:h2:test ),则数据库文件存储在启动应用程序的目录(当前工作目录)中。当从开始菜单使用H2控制台应用程序时,这是<安装目录> / bin 。可以在数据库URL中设置基本目录。可以使用固定或相对路径。当使用URL jdbc:h2:file:data / sample 时,数据库存储在目录数据中(相对于当前工作目录)。如果目录不存在,则自动创建该目录。也可以使用完全限定的目录名(对于Windows,驱动器名)。示例:
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.
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?
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.
Thanks!
解决方案Read the 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>. 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的嵌入式数据库在哪里存储数据?
发布评论