Java 如何根据我的 SQuirrel 配置找到嵌入式 h2 db?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19231155/
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-08-12 15:17:01  来源:igfitidea点击:

How can I locate an embedded h2 db based on my SQuirrel configuration?

javasqldatabaseh2

提问by membersound

I have a simple h2 database example, I assume it is a database that is stored in a single file. But where do I find this file? I'd like to connect to that db using SQL clients like Squirrel. Where is this file placed by default?

我有一个简单的 h2 数据库示例,我假设它是一个存储在单个文件中的数据库。但是我在哪里可以找到这个文件?我想使用 Squirrel 等 SQL 客户端连接到该数据库。这个文件默认放在哪里?

    <property name="eclipselink.jdbc.platform"
        value="org.eclipse.persistence.platform.database.H2Platform" />
    <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
    <property name="javax.persistence.jdbc.url" value="jdbc:h2:~/myDB;FILE_LOCK=NO" />
    <property name="javax.persistence.jdbc.user" value="sa" />
    <property name="javax.persistence.jdbc.password" value="sa" />

采纳答案by cmd

Based on the following value:

基于以下值:

jdbc:h2:~/myDB;FILE_LOCK=NO"

It appears that your database file is located in your home directory in a file called myDB

您的数据库文件似乎位于您的主目录中名为 myDB

The ~denotes your home directory.

~表示你的home目录。

回答by Frederic Close

In your example the file is placed in the file myDB under your home (represented as ~) directory :

在您的示例中,该文件位于您的 home(表示为~)目录下的 myDB 文件中:

  <property name="javax.persistence.jdbc.url" value="jdbc:h2:**~/myDB**;FILE_LOCK=NO" />

回答by yousafsajjad

You can use the following code to run H2 in server mode and connect using SQuirrl SQL client.

您可以使用以下代码在服务器模式下运行 H2 并使用 SQuirrl SQL 客户端进行连接。

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:target/h2/ps;AUTO_SERVER=TRUE" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>

You can use SQuirrel SQL client (http://squirrel-sql.sourceforge.net/) to connect to you H2 database and look at the tables.

您可以使用 SQuirrel SQL 客户端 ( http://squirrel-sql.sourceforge.net/) 连接到您的 H2 数据库并查看表。

Create new connection. Select H2 in the driver dropdown menu Set url to your project target folder h2 folder (jdbc:h2:C:\projects\workspace\TestProject\target/h2/ps;AUTO_SERVER=true) Enter user name ("sa") Enter password ("")

创建新连接。在驱动程序下拉菜单中选择 H2 将 url 设置为您的项目目标文件夹 h2 文件夹 (jdbc:h2:C:\projects\workspace\TestProject\target/h2/ps;AUTO_SERVER=true) 输入用户名 ("sa") 输入密码("")