How can I connect with an SQL tool to an embedded h2 db?

安稳与你 提交于 2019-12-03 22:02:17

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

The ~ denotes your home directory.

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

<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.

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 ("")

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

  <property name="javax.persistence.jdbc.url" value="jdbc:h2:**~/myDB**;FILE_LOCK=NO" />
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!