Why are added tables from Java not visible when I open the H2 console?

北慕城南 提交于 2019-12-02 05:57:21

问题


I use an H2 embedded database in Java, and after creating the database and adding some tables and data, it gets saved as a file in a directorey of my computer.

But whenever I open this file with the H2 Console, it shows no tables at all? Why are the tables not there?

I am using this URL in my java code: jdbc:h2:file://C:/Temp/H2/ourDB

And I log into the console with the following information:

After logging in, I can't see the tables that were created in Java?


回答1:


You have used a different database URL in the H2 Console (not jdbc:h2:file://C:/Temp/H2/ourDB). You need to use the same one, otherwise it's a different database.




回答2:


The accepted ans is correct- it's URL issue. But for recent user, I am posting the updated values (I am using SpringBoot 2 with Spring Data JPA). When you open H2 Console, the default URL shown for DB Connection is: jdbc:h2:~/test . If you connect using this URL, you won't find the tables you created in your app. But user generated tables to be seen use URL as jdbc:h2:mem:testdb. Pls, refer below figures:

Here EXCHANGE_VALUE was my JPA generated table, that i could see after connecting to db using URL as jdbc:h2:mem:testdb.



来源:https://stackoverflow.com/questions/24010737/why-are-added-tables-from-java-not-visible-when-i-open-the-h2-console

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!