H2控制台无法查看由JAVA创建的表 [英] H2 Console Cant see tables created by JAVA

查看:281
本文介绍了H2控制台无法查看由JAVA创建的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从 http://www.h2database.com/html/download.html
并且我已经在jdbc.properties文件中配置了URL
jdbc:h2:c:/data/Messaging.

I have downloaded the H2 console from http://www.h2database.com/html/download.html
and I have configured the URL in my jdbc.properties file
to jdbc:h2:c:/data/Messaging.

我在文件中使用相同的URL连接到数据库,但是看不到表格; 我只能看到信息模式,而当我尝试在其中输入select * from tables时,我也看不到表格.

I am using the same URL in the file to connect to the database but I cannot see the tables; I can only see the Information Schema and when I try to select * from tables in it I cannot see the tables neither.

有人知道什么地方可能出问题吗?

Does anybody have any idea what could be wrong?

推荐答案

一件棘手的事情是,如果您尝试连接到不存在的JDBC URL,则H2控制台不会给您错误.相反,它将在该URL处创建一个新数据库!要连接到内存数据库,请使用以下JDBC URL( http://localhost:8080/h2-console 是默认控制台):

One tricky thing is that the H2 console will not give you an error if you try to connect to a JDBC URL that doesn't exist. It will instead create a new database at that URL! To connect to the in memory DB, use this JDBC URL (http://localhost:8080/h2-console is the default console):

jdbc:h2:mem:testdb

如果要输入类似jdbc:h2:〜/test之类的内容,则会在主目录下创建一个test.mv文件.但是您的应用程序仍将使用内存数据库.

If you were to enter something like jdbc:h2:~/test then a test.mv file would be created under your home directory. But your application would still be using the in memory database.

如果您在pom中具有h2依赖性,并且还具有spring开发人员工具依赖性,则可以使用该控制台.如果您没有工具依赖项,那么还可以通过拥有h2依赖项并将以下内容添加到application.properties文件中来查看它:

The console is available if you have the h2 dependency in your pom, and also the spring developer tools dependency. If you don't have the tools dependency, then you can also see it by having the h2 dependency and adding the following to your application.properties file:

spring.h2.console.enabled=true  #not needed if you have spring-boot-devtools dependency

如果要将数据库作为文件而不是在内存中,请将以下内容添加到applications.properties:

If you want the db as a file, and not in memory, add the following to applications.properties:

spring.datasource.url=jdbc:h2:~/test_db  #You will see the file in your home directory.

H2并非用于持久数据,但是如果您出于测试目的而持久,请添加:

H2 isn't meant for persisted data, but if you want to persist for testing purposes, then add:

spring.jpa.hibernate.ddl-auto = update

然后启动应用程序,并在控制台上使用以下JDBC URL:

Then start up the app, and at the console, use this JDBC URL:

jdbc:h2:~/test_db

如果您想知道,在application.properties中(对于数据库文件)我只有1个条目,这是我的依赖项:

In case you were wondering, I only have 1 entry in application.properties (for the database file) and here are my dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
</dependency>

这篇关于H2控制台无法查看由JAVA创建的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆